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 65 66 67 68 69
|
#include <iostream>
#include <cctype>
using namespace std;
/********************PROTOTYPES**************************/
void getValues(float userVals[], const int number);
float getTotal (float userVals[], const int number);
float getAverage(const int number, float total);
void everything(float userVals[], float total, float average);
/***********************************************************/
int main(){
float userVals[20];
const int number = 20;
float total;
float average;
getValues(userVals, number);
getTotal(userVals, number);
getAverage(number,total);
everything(userVals, total, average);
return 0;
}
/**********************Functions************************/
void getValues(float userVals[], const int number){
int i = 0;
for (i = 0; i < number; ++i) {
cout << "Enter 20 integer values greater then zero and less than 100 " << endl;
cin >> userVals[i];
if (userVals[i] < 0 || userVals[i] > 100 ){
cout << "You have entered an invalid number, please enter another!" << endl;
i--;
}
else
continue;
}
}
float getTotal (float userVals[], const int number){
float total;
total = 0;
int index;
for(index=0; index < number; index++){
total = total + userVals[index];
}
return total;
}
float getAverage(const int number, float total){
float average;
average = total / number;
return average;
}
void everything(float userVals[], float total ,float average){
int count;
for (int count = 0; count < 19; count++){
cout<< userVals[count]<< " " << endl;
}
cout << "The total is " << total << endl;
cout << "the average is " << average<< endl;
}
|