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
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