# Thread: Choices using the if statements

1. ## Choices using the if statements

What this program should do is to enter radius then pick choices....
but it doesn't seem to work
the problem lies with the choice part in which when you type A or a, it will output the radius... when you type B or b circumference... and for C and c --- the area...

Code:
```#include <stdio.h>
#include <conio.h>
#define PI 3.14159

int main(void)
{
float r,circ,area;
char c;

clrscr();

scanf ("%f",&r);

printf ("\n[b] circumference");
printf ("\n[c] Area of Circle\n");
scanf ("%f",&c);
c = getche();

if (c == 'a' || c == 'A') {
gotoxy (38,12);
printf ("The radius of the circle is %f", r);
}
else if (c == 'b' || c == 'B') {
gotoxy (38,12);
circ = 2 * PI * r;
printf ("Circumference: %f", circ);
}
else if ( c== 'c' || c== 'C') {
gotoxy (38,12);
area = PI * r *r;
printf ("Area: %f", area);
}
else
{
gotoxy (38,12);
printf ("Invalid Choice");
}
getch();
}``` 2. To read in a single character, use
Code:
`scanf (" %c", &c);`
Note the leading space, that tells scanf to skip all leading whitespace. 3. but it doesn't seem to work
How does it not seem to work? What do you type in for input? What do you get for output? Are the results of the calculations wrong?

Code:
```char c;

...

scanf ("%f",&c);
c = getche();```
Why are you using %f to read in a character? That should be a %c. Also, why would you then immediately throw away the scanned value by overwriting it with the return result from getche? That's probably the problem, you are overwriting the value you scanned earlier in the previous statement. 4. thx for the help Popular pages Recent additions 