A quark in GCC

stylewise

Registered
Hey Guys,


I'm using OSX in my first C class. To practice nested if statements I wrote the following source code:

#include stdio.h // Tags are around that, won't show in fourm

int main (void) {

char gender;
int age;
double risk;

printf("enter your age ");
scanf("%d", &age);
fflush(stdin);
printf ("Enter your gender either m of f");
scanf("%c", &gender);
fflush(stdin);
if (gender == 'm' || gender == 'M')
if (age <= 50)
risk = .3;
else
risk = .6;
else if (gender =='f' || gender == 'F')
if (age <= 50)
risk = .8;
else
risk = .6;
else
printf("You entered somthing wrong/n");

return 0;
}


really basic. It compiles fine, however when your run it, the program exits after taking the age. It runs perfectly after compiled on devC++ or Microsoft Visual C++ on Windows. This could be a compiler quark in gcc, or is it something else?

Thank you in advanced,

Stylewise
 

jdog

Not a Moderator
I don't know if fflush is not working right or what, but the problem is when you hit enter after inputing the age, the return is being read as the input for the sex . Does that make sense?

-jdog
 
Top