-1

I Keep getting an error while trying to make a BMR Calculator that asks for the users age, weight, height and gender. I'm using an if statement to determine which formula for BMR to print. But I keep getting the error:

Cannot implicitly convert type int to bool

I'm a beginner and have never seen them before. Here is my code.

public static void Main (string[] args)
{
    int weight, height, age, gender;

    Console.Write("Enter your age in years");
    age = Convert.ToInt32 (Console.ReadLine());
    Console.WriteLine ("Enter your weight in pounds");
    weight = Convert.ToInt32 (Console.ReadLine());
    Console.WriteLine ("Enter your height in inches");
    height = Convert.ToInt32 (Console.ReadLine ());

    Console.WriteLine ("Gender? Enter male/female (1 for Male, 2 for Female)");
    gender = Convert.ToInt32 (Console.ReadLine());

    if (gender = 1)
    {
        Console.WriteLine ("Age: " + age);
        Console.WriteLine ("Height:" + height);
        Console.WriteLine ("Weight:" + weight);
        Console.WriteLine ("Gender:" + gender);

        Console.WriteLine ("Your BMR is" + 66 + (6.23 * weight) + (12.7 * height) - (6.8* age));
    }

    if (gender = 2)
    {
        Console.WriteLine ("Age: " + age);
        Console.WriteLine ("Height:" + height);
        Console.WriteLine ("Weight:" + weight);
        Console.WriteLine ("Gender:" + gender);

        Console.WriteLine ("Your BMR is " + 655 + (4.35 * weight) + (4.7 * height) - (4.7 * age));
    }
}
Adrian Sanguineti
  • 2,455
  • 1
  • 27
  • 29
Jason Shaft
  • 65
  • 1
  • 2
  • 8
  • 2
    `=` and `==` are different operators... – BradleyDotNET Jan 25 '17 at 00:21
  • Thanks, that helped for that error, still recieving "Operator "-" cannot be applied to operands of type string and double. – Jason Shaft Jan 25 '17 at 00:22
  • 1
    Add parentheses around your calculations so it's like `"Your BMR is" + (66 + ...)`. Your problem is order of operations. It's concatenating "Your BMR is" and "66" and then the next one and then the next one and then it gets to the `-` and throws its hands up. – itsme86 Jan 25 '17 at 00:23

1 Answers1

0

You need to cast the constant values to decimal and put a bracket around the calculation.

public static void BMR(string[] args)
{
    int weight, height, age, gender;

    Console.Write("Enter your age in years");
    age = Convert.ToInt32(Console.ReadLine());
    Console.WriteLine("Enter your weight in pounds");
    weight = Convert.ToInt32(Console.ReadLine());
    Console.WriteLine("Enter your height in inches");
    height = Convert.ToInt32(Console.ReadLine());

    Console.WriteLine("Gender? Enter male/female (1 for Male, 2 for Female)");
    gender = Convert.ToInt32(Console.ReadLine());

    if (gender == 1)
    {
        Console.WriteLine("Age: " + age);
        Console.WriteLine("Height:" + height);
        Console.WriteLine("Weight:" + weight);
        Console.WriteLine("Gender:" + gender);

        Console.WriteLine("Your BMR is" + (66.0m + (6.23m * weight) + (12.7m * height) - (6.8m * age)));
    }
    else
    {
        Console.WriteLine("Age: " + age);
        Console.WriteLine("Height:" + height);
        Console.WriteLine("Weight:" + weight);
        Console.WriteLine("Gender:" + gender);

        Console.WriteLine("Your BMR is " + (655.0m + (4.35m * weight) + (4.7m * height) - (4.7m * age)));
    }
}