I made some changes to the code to see if it works, but it still is not working. So, can you post the correct coding for this program and provide an explanation with it too? Thank you so much, this assignment has been stressing me out so much!
Write a C++ console application that accepts up to 5 numbers from the user. Display
all numbers, the highest, the lowest, and the average of the numbers. Ask the user if
they want to continue entering another set of numbers.
Tell the user what the program is all about. Do NOT start the program with
“Enter a number”!!
4) Create an array to store the numbers.
5) The user does not have to enter all 5 numbers. They can enter fewer. However,
of course, you need at least two numbers to be able to look for the highest and
the lowest. Make sure you explain this to the user.
6) Create three functions to perform the following tasks:
a. Calculate the highest number.
b. Calculate the lowest number.
c. Calculate the average.
7) All three functions receive an array and its size, and return a single value.
8) Keep track of the number of the values the user enters. Remember, they do
not have to enter all 5 numbers.
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 add(double array1[], int number); // Prototype of the array function 'int '.
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'.
bool play_again;
int num_games = 0;
string play;
int num i = 5;
int main(){
double input[5]; // Declaring an array to use for the function arrays.
int num = populate(input, 5); // Calls the array function 'int populate'.
spit(input, num); // Calls the array function 'void split'.
add(input, num); // Calls the array function 'int plus'.
highest_value(input, num); // Calls the array function 'int highest_value'.
lowest_value(input, num); // Calls the array function 'lowest_value'.
average_number(input, num); // Calls the array function 'average_number'.
int populate(double array1[], int number){ // User declares input.
double input;
cout << endl << endl;
cout << " Hello welcome to my game. You could enter up to 5 numbers."; //Introduction to program.
cout << "Once you enter your desired numbers, the program will display up the highest, lowest, and average of numbers.";
cout << "Enjoy!";
// Ask how many
cout << "How many numbers do you want to enter?" << endl;
cin >> num;
for (int i = 0; i < number; i++){
cout << "enter value for item " << (i + 1) << ": "; //Enter value.
cin >> input;
cout << endl;
array1[i] = input;
}
// Ask if the player would like to play again.
cout << endl << endl << "Would you like to play again?: ";
cin >> play;
// Exit the loop if the player chooses no.
if (play == "n" || play == "N"){
play_again = false;
}
else if (play == "y" || play == "Y"){
num_games++;
}
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 add(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 numbers" << " = " << highest_value(input, num) << 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;
}
Please use code tags. Edit your post, highlight the code that you pasted in, and click the Format button that is labeled "<>". This should make it easier to read and comment on your code.
I made some changes to the code to see if it works, but it still is not working.
You need to be more specific. What is not working? How should it work?