1. ## Asks to input number nad if outside number asks to put in number within bounds

Hi all,
I have to write a program that will ask you to put in a number between 0 and 9 and multiply it by pi. If the number put in is between 0 and 9 then pi is multiplied but if it isnt between 0 or 9, it will say the number is not between 0 and 9 and asks you to put it in again and will repeat until a number between 0 and 9 is put in.
I have got the program working to the extent that it the number is between 0 and 9 it will multiply it by pi but if its not between 0 and 9 it will say the number is not between 0 and 9 and ask to put in a new number.
I can't work out how to get the program to repeat itself if the number entered isnt between 0 and 9.
I have enclosed the code below, can anyone help me with this?

2. I think this will work.
keep up on the indentation gook work!
Code:
```//S_Howlin 20/3/13
// Revision
// number between 0 and 9 by pi and check if value entered is between 0 and 9 and asks for new value if outside of 0 and 9

#include <stdio.h>
#include <math.h>
#include <conio.h>

int main ()

{
int x;
double y;
for(;;){             //This loop ensures that the program keeps asking for a number
printf ("Please enter a value between 0 and 9 (Enter a number less than 0 to terminate):  " ); // Asks to put in a value between 0 and 9 and a value less thatn 0 to terminate
scanf ( " %d", &x);
if(x<0){break;} // checks if the value entered is less than zero
if ( x > 0.0 && x < 9.0 ) // if the value is between 0 and 9 the following will be said:
{
printf( "The value entered is between 0 and 9 \n");
y = x * M_PI;  // works out value for y by multiplying x with pi
printf ( "The value for y is: %0.2f\n", y); // Works out value for y to 2 decimel places
}
else //If the value is not between 0 and 9 the follwoing will be siad:
{
printf( "The value you entered is NOT between 0 and 9. \n");
}
}

getch ();
return 0;
}```

3. You need to look up do ... whike loops. You ask for the number, then while it is bad, go back and ask again.

4. acho.arnold, it is a good idea to avoid doing people's homework for them as this site has a homework policy here.

In this case, it makes no difference as your solution does not meet requirements of the exercise anyway. And your code uses a few things that are not standard C (<conio.h>, getch(), M_PI).

As Malcolm suggested, a do/while loop is a more suitable solution.

5. I am not looking for someone to do it just for help, a guide on what way to go and do it.
I use the getch() as my lecturer uses bloodshed on lynix and the system ("pause") doesn't work on it.

Is using a do/while loop more suitable than an if/else loop?

6. Originally Posted by howlin
Is using a do/while loop more suitable than an if/else loop?
A do/while loop is a valid code construct in C. There is no such thing as an "if/else loop".

Practically, a valid code construct is usually considered more suitable than a non-existent one.