Create a C++ console application that uses a while loop to count, total, and average a series of positive integers entered by a user. The user enters a –1 to signal the end of data input and to display the count, total, and average of the numbers entered.
The pseudocode for the program is:
Start
Enter user's input
Begin Loop
While user's input is greater than sentinel
increment counter
add user's input to the sum
Enter user's input again
End Loop
Display messages
Stop
Exercise 2:
Write a program that uses at least one for loop to print a section of the multiplication table. The user should be able to specify the section of the table to be displayed. The program will also display a count of the number of rows printed, the count of the columns printed and the sum of all calculated values.
The user input will appear as such:
**Create a Multiplication Table**
Enter the starting value: 2
Enter the ending value: 5
The pseudocode for the program is:
Start
Enter user's Table dimension (start and end number)
Begin For Loop (colnum = startnumber, colnum<=endnumber, increment colnum)
display colnum
increment colnum
End For loop
initialize currentRow as startnumber
Begin while loop (until curentRow is less than or equal to endnumber)
display currentRow
increment Rowcount
Begin For Loop (colnum = startnumber, colnum<=endnumber, increment colnum)
display product of colnum and currentRow
Add the product of colnum and currentRow to the sum
End For Loop
increment currentRow
End of While Loop
Display row, col and sum printed
Stop
The output will be:
X 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
rows printed = 4
Columns printed = 4
Sum: 196
Exercise 3, last one
Create a C++ console application that generates a random number that must be guessed by a user. The program will indicate to the user if their guess is correct, too high or too low. It will also report the number of guesses the user has made. The game ends when the user enters a negative one (-1) or has guessed the number. The program should include a do while loop, decision statements, constants and variables.
The pseudocode for the program is:
Start
Generate a random number
Begin loop
Enter user's guess
If guess is right
Display message and exit loop
If guess is high
Display message
If guess is low display message
Display message
Increment counter
End loop
Display number of guesses
Stop
When the program is executed it will produce the following output:
**The Guessing Game**
Enter a Guess (-1 to exit):
After the user makes a guess the program will output one of these statements:
Too High, Try Again!
Too Low, Try Again!
You’ve guessed wisely!
After a correct guess or the user ends execution the program will output one of these statements:
The number was X it took you X guesses.
The number was X you gave up after X guesses.