Can Anyone Help Out a C++ Beginner with Code ASAP?

closed account (2zApDjzh)
Hello everyone. I really need some help from you guys since I'm a beginner to C++ and I need to get this program working properly. I made some changes to it to see if I fixed the problem, but it still is not working properly. So if you all could help me out and show me the correct coding and explain it I will really appreciate it. Thanks!

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.

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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
 #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 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'.

cout << endl;
cout << "------------------------------------------" << endl;

system("pause");
return 0;
}

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;
}
Topic archived. No new replies allowed.