-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcinfish.cpp
More file actions
36 lines (32 loc) · 803 Bytes
/
Copy pathcinfish.cpp
File metadata and controls
36 lines (32 loc) · 803 Bytes
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
#include <iostream>
const int Max = 5;
int main(int argc, char *argv[])
{
using namespace std;
double fish[Max];
cout << "Please enter the weights of your fish.\n";
cout << "You may enter up to " << Max << " fish <q to terminate>." << endl;
cout << "fish #1: ";
int i = 0;
while (i < Max && cin >> fish[i]){
if(++i < Max)
{
std::cout << "fish #" << i+1 << ": " ;
}
}
double total = 0.0;
for(int j = 0; j < i; j++)
{
total += fish[j];
}
if(i == 0)
{
std::cout << "No fish" << std::endl;
}
else
{
std::cout << total/i << " = average weight of " << i << " fish" << std::endl;
}
std::cout << "done." << std::endl;
return 0;
}