Simple Program not working right (in C)
I just made this C program in Codewarrior for mac using the "PPC console C App:"
#include <stdio.h>
#include <stdlib.h>
int main()
{
float fuel_flow;
float total_fuel;
float TAS;
char TAS1[6];
char total_fuel1[16];
char fuel_flow1[12];
char yn='y';
while(yn=='y')
{
printf("What is your fuel flow in pounds? ");
gets(fuel_flow1);
fuel_flow=atoi(fuel_flow1);
printf("What is your total fuel availible in pounds? ");
gets(total_fuel1);
total_fuel=atoi(total_fuel1);
printf("What is your true airspeed in knots? ");
gets(TAS1);
TAS=atoi(TAS1);
printf("\nEndurance: %.2f hrs\n",total_fuel/fuel_flow);
printf("Range: %.1f nm\n",total_fuel/fuel_flow*TAS);
printf("\nCalculate again? y/n ");
yn=getchar();
}
printf("Done!");
return 0;
}
Here is my problem. The first run of the program is good. After the program asks "Calculate Again?" , i type in "y" and then on the next line it prints the first two printfs; printf("What is your fuel flow in pounds? "); and printf("What is your total fuel availible in pounds? "); on the same line and everything gets messed up after that until i re run the program. Could there be something wrong in my while loop? It would be great if anyone can help. thank you.