How do I start this off?
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
|
#define MAX 10
#define NUM_PER_LINE 6
int main()
{
int i;
int arr[MAX = {0}; //array initialized to 0
int sum = 0;
double average = 0;
int smallest = 0, highest = 0;
int j; //cout number printed
//for-loop to enter MAX elements (10) to array arr
//for-loop to print all elements of array
//printing 6 (NUM_PER_LINE) elements per line
//for-loop to find sum of all elements of array
//same time, find the largest and smallest value
// in the array
//average calculate
//display average, highest and lowest value
cout << "\n\n";
return 0;
|
________________________________________________________________________________
1. Type code for program shown above.
2. In about line 20, implement a for-loop that will prompt user to enter
an integer number, and then assign number to each element of the
array starting from first element (subscript 0) to the last element
of array.
Output (and input) can be something like this
Enter value # 1: 23
Enter value # 2: 4
Enter value # 3: 76
Enter value # 4: 89
Enter value # 5: 12
Enter value # 6: 43
Enter value # 7: 37
Enter value # 8: 67
Enter value # 9: 21
Enter value # 10: 14
Note: You should variable I to control the loop which should start
from 0 but not the numbering displayed above start count from 1.
3. In about line 24 in the original figure above, implement a for loop
that will print all elements of the array and print NUM_PER_LINE
numbers per line.
Array elements are:
23 4 76 89 12 43
37 67 21 14
Note: I used to variable j (starting from 1) to count how many
numbers already printed. Once it is equal to NUM_PER_LINE, a new line
is printed and j is set to 1 again. Also note the numbers are aligned
nicely to the right.
4. In about line 29 in the original figure above, implement a for loop
that will do the following things: 1) Find the sum of all elements in
the array. 2) Find the largest value in the array and 3) Find the
smallest element in the array.
5. Once finished the loop in #4 above, display average to 2 decimal
place, and also display the highest and lowest value. Make sure the
output aligned nicely. See output below.
Average = 38.60
Highest = 89
_________________________________________________-
I do not know how to do for loops or arrays or even how to iterate (whatever that means). I am still reading on the topic and this is due in an hour.
Smallest = 4