I have to write the program, when after terminating infinite while loop "while(cin>>a)" by, let's say "-1", program says me how many times value increased. For input "0 0 2 2 3 4 8 8 8 -1" it should print "4". First part isn't problem, but I have no idea how to count how many times it had changed over time. Any tips? Thanks a lot.
You should use counters which will basically increase each time your value increases. Check the code bellow:
int value, highestValue, counter = 0, counter2 = 0;
do{
cout << "Enter the value: ";
cin >> value;
if(counter2 == 0){
highestValue = value;
}
if(value > highestValue){
counter++;
highestValue = value;
}
counter2++;
}while(value != -1);
cout << "The number increased " << counter << " times!\n";
The second counter (counter2) is required in the first if statement to store the first value you enter as the highest value.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments