How can i repeat a loop based on the number inputted by the user?
Anyone help me!!!![]()
How can i repeat a loop based on the number inputted by the user?
Anyone help me!!!![]()
Code:int num=0; int value=0; printf("HOW MANY INTEGER VALUES WOULD YOU LIKE INPUT?"); scanf_s("%d",&num); do { printf("Value:"); scanf_s("%d",&value); }while(value!=num); /*this is what i did but this is not right, supposedly the output must be like this: How many integer values would you like to input? 5 <-------then the range of value i need to input will be only five value:5 value:8 value:4 value:9 value:2 (and must automatically terminate) it's a bit confusing but i wonder you could help, please =( */
What you have done is say, "loop until the input number (value) does not equal the first number (num)".
Why not decrement the value of "num" every loop and loop until it equals 0?
Fact - Beethoven wrote his first symphony in C
I'd actually recommend a "for()" loop for this purpose, since it is well suited for what you're trying to do (variable update and conditional check "built in"). However, a "while()" is also perfectly acceptable, if used correctly.
For, While and Do While Loops in C - Cprogramming.com