I have been working on the following problem the entire weekend:
Write a program that repeatedly asks for positive integers (values greater than or equal to 1). The user
may type 0 to quit the program. The user will enter at least one value before typing 0 to quit. After the
user types 0 to quit, your program should report how often the largest number was entered.
My teacher said that he wrote this program using only a while loop and two if statements, I understand how to use the while loop. However I am not sure how to display the largest value of all the numbers or print how often that number was entered. I also understand that all the numbers entered must be stored in order to compare them. I would greatly appreciate help or some hints on this.
Create two variables, one to store the current max value and one to store the number of times it's entered ( initialize both to 0 )
When a number is entered use those variables to keep track of the max value
int maxValue = 0;
while( user does not enter 0 )
{
if value user just entered is greater than maxValue
then set maxValue to that value
}
print out maxValue