Reputation: 95
I have no idea know what's wrong with my if statement. The program just switch off after Asked the user to enter their gender. Enter 1 If you are Male Enter 2 If you are Female
static void Main(string[] args) {
int WaistToHeightCalculatorOption,GenderOption;
double HeightCm = 0.0, WaistCm = 0.0;
double WaistToHeightRatio = 0.0;
string WaistToHeightCalculatorMenu = ("Which Measurement You Want to use to enter the weight and height?"
+ "\n1)Enter 1 for Metric"
+ "\n2)Enter 2 for British Imperial:");
Console.Write(WaistToHeightCalculatorMenu);
WaistToHeightCalculatorOption = int.Parse(Console.ReadLine());
if (WaistToHeightCalculatorOption == 1) {
Console.Write("\nPlease Enter your Height in cm:");
HeightCm = double.Parse(Console.ReadLine());
Console.Write("\nPlease Enter your Waist in centimetres (cm):");
WaistCm = double.Parse(Console.ReadLine());
WaistToHeightRatio = WaistCm / HeightCm;
Console.WriteLine("Your Waist to Height Ratio is {0}", WaistToHeightRatio);
Console.Write("\n1)Enter 1 If you are Male"
+ "\n2)Enter 2 If you are Female:");
GenderOption = int.Parse(Console.ReadLine());
if (GenderOption ==1) {
if (WaistToHeightRatio >= 0.536) {
Console.WriteLine("Your Risk of Obesity Related Cardiovascular Diseases is at High Risk");
} else if (WaistToHeightRatio < 0.536) {
Console.WriteLine("Your Risk of Obesity Related Cardiovascular Diseases is at low Risk");
}
} else if (GenderOption == 2) {
if (WaistToHeightRatio >= 0.492) {
Console.Write("Your Risk of Obesity Related Cardiovascular Diseases is at High Risk");
} else if (WaistToHeightRatio < 0.492) {
Console.Write("Your Risk of Obesity Related Cardiovascular Diseases is at low Risk");
}
}
}
Upvotes: 0
Views: 820
Reputation: 5260
Because after the last input , you just print to screen and exit the program.
Also your indentation can be confusing, I think this way is more readable.
what happens if gender is not 1 or 2 ? you should let the user know that he make a mistake , or loop till you get what you want (1 or 2)
if (GenderOption ==1){
if (WaistToHeightRatio >= 0.536) {
Console.WriteLine("Your Risk of Obesity Related Cardiovascular Diseases is at High Risk");
}
else {
Console.WriteLine("Your Risk of Obesity Related Cardiovascular Diseases is at low Risk");
}
}
else
if (GenderOption == 2) {
if (WaistToHeightRatio >= 0.492) {
Console.Write("Your Risk of Obesity Related Cardiovascular Diseases is at High Risk");
}
else {
Console.Write("Your Risk of Obesity Related Cardiovascular Diseases is at low Risk");
}
}
Upvotes: 1
Reputation: 544
You can just press Ctr + F5 in Visual Studio or add Console.ReadKey();
at the end to wait for user to enter any key before exit the program.
Upvotes: 2