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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>
#include <ctime>
using namespace std;
int populate(double array1[], int number); // Prototype of the array function 'int populate'.
void spit(double array1[], int number); // Prototype of the array function 'void split'.
int plus(double array1[], int number); // Prototype of the array function 'int plus'.
int highest_value(double array1[], int number); // Prototype of the array function 'int highest_value'.
int lowest_value(double array1[], int number); // Prototype of the array function 'int lowest_value'.
int average_number(double array1[], int number); // Prototype of the array function 'int average_number'.
int main(){
double input[5]; // Declaring an array to use for the function arrays.
populate(input, 5); // Calls the array function 'int populate'.
spit(input, 5); // Calls the array function 'void split'.
plus(input, 5); // Calls the array function 'int plus'.
highest_value(input, 5); // Calls the array function 'int highest_value'.
lowest_value(input, 5); // Calls the array function 'lowest_value'.
average_number(input, 5); // Calls the array function 'average_number'.
cout << endl;
cout << "------------------------------------------" << endl;
system("pause");
return 0;
}
int populate(double array1[], int number){ // User declares input.
double input;
cout << endl << endl;
for(int i = 0; i < number; i++){
cout << "enter value for item " << (i + 1) << ": ";
cin >> input;
cout << endl;
array1[i] = input;
}
cout << "------------------------------------------" << endl;
return input;
}
void spit(double array1[], int number){ // The console prints what the user input.
cout << endl << endl << "CONSOLE LOG" << endl;
cout << "You entered: " << endl;
for(int i = 0; i < number; i++){
cout << endl;
cout << endl << "the value of item " << (i + 1) << " = " << array1[i];
}
cout << endl << endl << "-------------------------------------------" << endl;
}
int plus(double array1[], int number){ // + together the users input, so it = total amount.
int sum = 0;
for(int i = 0; i < number; i++){
sum += array1[i];
}
cout << endl << endl << "The total of all the 5 numbers" << " = " << sum << endl << endl;
return sum;
}
int highest_value(double array1[], int number){ // Finds the highest value the user input.
int temp = 0;
for(int i = 0; i < number; i++){
if(array1[i] > temp)
temp = array1[i];
}
cout << endl << "The highest value of all the 5 numbers" << " = " << temp << endl << endl;
return temp;
}
int lowest_value(double array1[], int number){ // Finds the lowest value the user input.
int small = array1[0];
for(int i = 0; i < number; i++){
if(array1[i] < small)
small = array1[i];
}
cout << endl << "The lowest value of all the 5 numbers" << " = " << small << endl << endl;
return small;
}
int average_number(double array1[], int number){ // Finds the average number the user input.
double sum = 0;
for(int i = 0; i < number; i++){
sum += array1[i];
}
sum = sum / number;
cout << endl << "The average value of all the 5 numbers" << " = " << sum << endl << endl;
return sum;
}
|