Complete the do-while loop to output every number from 0 to countlimit using printval. assume the user will only input a positive number. for example, if countlimit is 5 the expected output will be 0 1 2 3 4 5

Question
Answer:
Hi, here's a do-while loop using C++ programming language. 

int countlimit; //input from user
int printval =0; //initial value of printval


cout<<"Enter a positive number:"; //suppose user inputs 5
cin>>countlimit; //value 5 will be stored inside variable countlimit
do{ //start of do-while loop
cout<<printval; //print initial value
printval++; // increment printval 

}while(printval>=countlimit); //if condition is true, loops back to beginning of do

Loops ends and stops printing if countlimit (of 5, in this example) is reached. 


solved
general 10 months ago 6962