I'm in an intro computer science class so I'm very new to programming. Below is the assignment. I did get my program to compile, but it doesn't work properly when you first enter a number between 1 and 10. It only works when you enter it incorrectly first. What did I do wrong? Should I be using a different loop? Any insight would be greatly appreciated!
Goal: Write a program that asks the user for a number to count to (in the range of 1 to 10), once the user has entered in an appropriate number, count to that number
◦ Ask the user to enter a number between 1 and 10.
◦ If the user did so correctly, count from 0 to the number entered by the user.
◦ If the user did not enter the number correctly, tell the user “I’m sorry, that is incorrect.” and then prompt the user to enter the number again. Repeat as many times as necessary.
◦ You must use two different loop types.
Code:#include <stdio.h> int main(void) { //DECLARE VARIABLES int i, stored_number; //PURPOSE OF PROGRAM printf ("\nThis program will count from 0 to a number you pick.\n"); //PICK AND STORE NUMBER printf ("\nPlease enter a number (between 1 and 10):"); scanf ("%d", &stored_number); //DO LOOP i=1; do { printf ("\nI'm sorry, that is incorrect.\n"); printf ("Please enter a number (between 1 and 10):"); scanf ("%d", &stored_number); } while (stored_number>10); printf ("\n"); //WHILE LOOP printf ("\n"); i=0; while (i<=stored_number) { printf ("%d...", i); i++; } printf ("done!"); //END PROGRAM printf ("\n\n"); return 0; }