=====Sum and average all of the odd and even numbers entered by the user.
When the program runs it should look like this:
How many numbers will you enter? 3
Enter number 1: 20
Enter number 2: 25
Enter number 3: 44
The odd numbers are 25
The total of the odd numbers is 25, the average is 25
The even numbers are 20 44
The total of the even numbers is 64, the average is 32
|
Step #4: LoopingSo far the code looks like this:
But our program needs a loop so it will ask for as many numbers as the user wants, not just one number. Do you remember back at Step #1 where the user typed in a number, called total, to decide how many numbers will be entered and analyzed? for (int n = 1; n<= total; n++){ // prompt the user to enter number n // read in the number and call it num // add num to either sumOdd or sumEven // join num as a string to either numberStringEven or numberStringOdd
|
<-- Previous |