So i'm honetly having trouble doing this program, I feel like it's simple, but I'm not sure how to even do the display part of the assignment.
the assignment is as follows:
Create a program that:
1. Prompts the user to input values for an array of five integers
2. Displays a menu, where the user may choose
a. Sum - Calculates and displays the sum of numbers in the array
b. Mean - Calculates and displays the average of numbers in the array
c. Display - Displays the current values held in the array
d. Edit - The user is re-prompted for input into the array
e. Exit - terminate the program
3. Loop back to step 2
a. There should be at least 3 functions used in this program
You should probably use a global const int for array size. Do not use global variables unless they’re constants!
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
|
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const int SIZE = 5;
int array[SIZE];
int displayArray()
{
const int SIZE = 5;
int array[SIZE];
//////////////////
//Display of Array
cout << "The numbers you entered are as follows: ";
cout << " " << array[0];
cout << " " << array[1];
cout << " " << array[2];
cout << " " << array[3];
cout << " " << array[4];
cout << endl;
return array[4];
}
int main ()
{
const int SIZE = 5;
int array[SIZE];
/////////////////////
//User Input of Array
cout << "Enter first number: \n";
cin >> array[0];
cout << "Enter second number: \n";
cin >> array[1];
cout << "Enter third number: \n";
cin >> array[2];
cout << "Enter fourth number: \n";
cin >> array[3];
cout << "Enter fifth number: \n";
cin >> array[4];
/* //////////////////
//Display of Array
cout << "The numbers you entered are as follows: ";
cout << " " << array[0];
cout << " " << array[1];
cout << " " << array[2];
cout << " " << array[3];
cout << " " << array[4];
cout << endl; */
displayArray();
//////////////
//Sum of Array
float average, sum = 0;
for (int tnum = 0; tnum < SIZE; tnum++)
sum += array[tnum];
///////////////
//Mean of Array
average = sum/SIZE;
////////
//Output
cout << "sum: " << sum << endl;
cout << "average: " << average << endl;
system ("read");
return 0;
}
|