Hi guys! can you help a novice programmer here. I've been working on a Try again decision using the Do-While loop. Heres the code I've established.
Code:
#include <stdio.h>
int main(void)
{
// Declaration of Variables
double Pounds = 0;
double Kilograms = 0;
double Inches = 0;
double Meters = 0;
double BMI = 0;
char ans1 = ' ';
char ans2 = ' ';
char ans3 = ' ';
do
{
{
printf("Please enter your height(Meters): ");
scanf("%lf", &Meters);
printf("Please enter your weight(Kilograms): ");
scanf("%lf", &Kilograms);
BMI = Kilograms/(Meters*Meters);
printf("Your BMI (Meters&Kilograms) is: %.2f\n", BMI);
}
printf("Would you like to try again? (y/n): ");
scanf("%c", &ans1);
fflush(stdin);
}
while (ans1 =='y');
}
The whole thing works until I reach the try again decision.
Code:
Please enter your height(Meters):
1.6
Please enter your weight(Kilograms):
52
Your BMI (Inches&Pounds) is: 20.31
Would you like to try again? (y/n):
Program ended with exit code: 0
This is what I always end up with. I would really appreciate the help