-
Notifications
You must be signed in to change notification settings - Fork 0
/
Arrays.cpp
64 lines (47 loc) · 1.55 KB
/
Arrays.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Author: Josuel Musambaghani
// The following program skeleton contains a 10-element array of int s called fish .
// When completed, the program should ask how many fish were caught by fishermen
// 1 through 10, and store this data in the array. And then the program will display
// number of fish caught by each fisherman by determining the lowest and the highest.
#include <iostream>
#include <string>
using namespace std;
int main()
{
const int NUM_FISH = 3;
int fish[NUM_FISH];
// You must finish this program. It should ask how
// many fish were caught by fishermen 1-20, and
// store this data in the array fish.
for (int num = 0; num < NUM_FISH; num++)
{
cout << "Enter the number of fish caught: ";
cin >> fish[num];
}
// display the number of fish caught
for (int num = 0; num < NUM_FISH; num++)
{
cout << "The number of fish caught fish caught by fisherman " << num+1 <<" is: " << fish[num] << endl;
}
// looking for the lowest number of fish caught
int min = fish[0];
for (int num = 0; num < NUM_FISH; num++)
{
if (min > fish[num])
{
min = fish[num];
}
}
cout << "The lowest: " << min << endl;
// looking for the highest number of fish caught
int max = fish[0];
for (int num = 0; num < NUM_FISH; num++)
{
if (max < fish[num])
{
max = fish[num];
}
}
cout << "The highest: " << max << endl;
return 0;
}