-4

I am trying to get the user to re enter the the number again if they enter a value of less than ten i am certain the problem lies with the while statement. this what i have

printf_s("Enter the player first name: ");
scanf_s("%s", names[i], 25);  //enters name and creates a newline <enter key>//

printf_s("Minimum number to stop in a turn: ");
scanf_s("%d", &min_number, sizeof(int));
do {
printf_s("please enter a number greater or egual to 10");
} while (min_number <= 10);
        scanf_s("%d ", &min_number);
        printf_s("please enter a number greater or equal to 10\n\n");

is a do while loop the best option or should i look at using another type of loop

enter image description here

  • 3
    I think you need to [find a good beginners book](http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list) and read more about `while` (both variants). – Some programmer dude Jun 06 '17 at 11:55
  • You are using a `while`like a `for`and you need to format correctly your code. Also, there is an extra paranthesis and semi-colon and in the beginning of the `while`which is harmful **and** useless – Badda Jun 06 '17 at 11:56
  • It looks like you're confusing a `do... while` and `while` loop. – Carcigenicate Jun 06 '17 at 11:59

1 Answers1

0

As I was corrected, thoughfully scanf returns the number of receiving arguments successfully assigned. Here is a fixed version:

void main(){
        int num = 0;
     while(num <=10){ 
         scanf("%d ", &num);
         printf_s("please enter a number greater or equal to 10\n\n");
     }
 }

After the authour edited the code in his question and upon his request:

do {
        printf_s("please enter a number greater or egual to 10\n\n");
        scanf_s("%d", &min_number);
    } while (min_number < 10);

When doing the do/while loop the body of the loop is in the do{body goes here}while(some condition);.

After another edit, on author request:

printf_s("Minimum number to stop in a turn: ");
    scanf_s("%d", &min_number, sizeof(int));

    while(min_number < 10){
        printf_s("please enter a number greater or egual to 10\n\n");
        scanf_s("%d", &min_number);

    }

This will do the following it will ask for "Minimum number to stop in a turn: " if it is greater or equal to 10 it will continue after the loop. If it is not it will give clarification "please enter a number greater or egual to 10" and will receive another input. It will loop until it receive greater or egual to 10.

du4ko
  • 101
  • 6
  • i updated my code the problem is if i enter a number greater than 10 it ask me "please enter a number greater or equal to 10" if it is less than 10 it runs the loop "please enter a number greater or equal to 10" forever. the condition i was going for is for the user to renter that number so it is greater or equal to 10 and then continue on with the rest of the program – Elijah Ceeney Jun 06 '17 at 12:31
  • im almost there the problem is that if it is 10 or greater i have to enter this value twice before the program proceeds. it ask "Minimum number to stop in a turn:" then it ask "please enter a number greater or equal to 10" if it less than 10 it keeps asking "please enter a number greater or equal to 10" which is what i want – Elijah Ceeney Jun 06 '17 at 12:54
  • Sorry I am not able to undestand what are you trying to sayhere. You need to read more data after the number is greater than 10? – du4ko Jun 06 '17 at 12:59
  • `int min_number; printf_s("Minimum number to stop in a turn: "); scanf_s("%d", &min_number, sizeof(int)); do { printf_s("please enter a number greater or egual to 10\n\n"); scanf_s("%d", &min_number); } while (min_number < 10);` Do you mean this? – du4ko Jun 06 '17 at 13:02
  • The above code do what exactly you are asking. It will ask for number after the Minimum number is given, if the number is greater than 10 it will stop the loop and continue below if the number is less it will ask it until it is equal or more than 10. – du4ko Jun 06 '17 at 13:12
  • Ive added a pic in the question. this is what i get Mary shouldnt be asked the question but john should until he enter 10 or more – Elijah Ceeney Jun 06 '17 at 13:47
  • Well from the screenshot I am seeing you are getting the correct behaviour. What part of the output is troubling you? You want to take the names frist and then being asked about the numbers? – du4ko Jun 06 '17 at 13:55
  • i dont want mary to be asked that question because she entered 11 when she was asked "minimum number of turns to stop" so that is greater than 10 so the program should proceed and should not display "please enter a number greater or egual to 10\" but since john answered 9 to the question of "minimum number of turns to stop" he needs to be asked "please enter a number greater or equal to 10" until he enter 10 or more. – Elijah Ceeney Jun 06 '17 at 14:01
  • So basicly what you want is , when Mary enters her number for "minimum number of turns to stop" , if it is more than 10 to directly asks John for "minimum number of turns to stop" and if he enters a number less than 10 to ask him to enter bigger number? So what happens if Mary enters a number less than 10? – du4ko Jun 07 '17 at 06:01
  • Check my answer, again I have add another snippert with explanation ( the third one). Was this what you were looking for? – du4ko Jun 07 '17 at 06:11