I’m new to C# and have made a few working console applications such as Hello World and a BMI Calculator.
I’m trying to make a weight converter from imperial to metric and vice versa now, but I’m having trouble letting the user choose which they would like to do. This is the segment of code I am struggling with:
decimal pounds;
decimal poundsconverted;
decimal kilo;
decimal kiloconverted;
string choice;
Console.WriteLine ("Press 1 to convert from imperial to metric");
Console.WriteLine ("Press 2 to convert from metric to imperial");
choice = Console.ReadLine();
if (choice (1))
Console.WriteLine ("Please enter the weight you would like to convert in pounds (lbs) ex. 140");
pounds = Convert.ToDecimal (Console.ReadLine());
poundsconverted=pounds/2.2;
Console.WriteLine("The weight in kilograms is:{0:F3}", poundsconverted);
if (choice (2))
Console.WriteLine ("Please enter the weight you would like to conver in kilograms (kg) ex. 80");
kilo = Convert.ToDecimal (Console.ReadLine());
kiloconverted=pounds*2.2;
Console.WriteLine("The weight in pounds is:{0:F3}", kiloconverted);
My problem is with the if statements. I have tried multiple formats but to no avail. Is there a better method to do this? is it possible with if statements?
use
switch/ caseorif/elsehere is the sample for switch/case