BMI [C#]计算器具有常规计算器 - 主计算器问题(Schoolboy Error?)

时间:2013-10-01 17:13:45

标签: c# calculator

所以我最近制作了一个计算器作为我的A-Level计算类的一部分,它工作得很好然后我的老师告诉我添加一个BMI计算器,它再次正常工作,但现在问题是计算器没有运行。这是代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Calculator1
{
class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello! Type BMI to head to the BMI Calulator");
        Console.WriteLine("If you want a calculator -- Here are your commands:");
        Console.WriteLine("TIMES - ADD - SUBTRACT - DIVIDE");
        string text = Console.ReadLine();
        if (text == "BMI")
        {
            Console.Clear();
            Console.WriteLine("Welcome to the BMI Calcualtor! Please enter your height (M)");
            string height = Console.ReadLine();
            Double height1 = Convert.ToDouble(height);
            Double height2 = height1 * height1;
            Double heightB = Convert.ToDouble(height2);
            Console.Clear();
            Console.WriteLine("Please enter your Weight(KG)");
            string weight = Console.ReadLine();
            int weight1 = Convert.ToInt32(weight);
            Double weightA = Convert.ToDouble(weight1);
            Double fbmi = weightA / heightB;
            Console.WriteLine(fbmi);
            if (fbmi < 18.5)
            {
                Console.WriteLine("UnderWeight");
                Console.ReadLine();
            }
            if (fbmi > 18.5&& fbmi < 25.0)
            {
                Console.WriteLine("Normal");
                Console.ReadLine();
            }
            if (fbmi > 25.0 && fbmi < 29.9)
            {
                Console.WriteLine("OverWeight");
                Console.ReadLine();
            }
            if (fbmi > 29.9 && fbmi < 40.0)
            {
                Console.WriteLine("Obese");
                Console.ReadLine();
            }
            if (fbmi > 40.1)
            {
                Console.WriteLine("Extremely Obese");
                Console.ReadLine();
            }
            if (text == "TIMES")
            {
                Console.WriteLine("Enter your first number");
                string number = Console.ReadLine();
                int NumberA = Convert.ToInt32(number);
                Console.WriteLine("Enter your second number");
                string number1 = Console.ReadLine();
                int NumberB = Convert.ToInt32(number1);
                Console.WriteLine("");
                Console.WriteLine("============");
                Console.WriteLine("ANSWER");
                Console.WriteLine("============");
                Console.WriteLine(NumberA * NumberB);

                Console.ReadLine();
            }
            if (text == "ADD")
            {
                Console.WriteLine("Enter your first number");
                string number = Console.ReadLine();
                int NumberA = Convert.ToInt32(number);
                Console.WriteLine("Enter your second number");
                string number1 = Console.ReadLine();
                int NumberB = Convert.ToInt32(number1);
                Console.WriteLine("");
                Console.WriteLine("============");
                Console.WriteLine("ANSWER");
                Console.WriteLine("============");
                Console.WriteLine(NumberA + NumberB);

                Console.ReadLine();
            }
            if (text == "SUBTRACT")
            {
                Console.WriteLine("Enter your first number");
                string number = Console.ReadLine();
                int NumberA = Convert.ToInt32(number);
                Console.WriteLine("Enter your second number");
                string number1 = Console.ReadLine();
                int NumberB = Convert.ToInt32(number1);
                Console.WriteLine("");
                Console.WriteLine("============");
                Console.WriteLine("ANSWER");
                Console.WriteLine("============");
                Console.WriteLine(NumberA - NumberB);

                Console.ReadLine();
            }
            if (text == "DIVIDE")
            {
                Console.WriteLine("Enter your first number");
                string number = Console.ReadLine();
                int NumberA = Convert.ToInt32(number);
                Console.WriteLine("Enter your second number");
                string number1 = Console.ReadLine();
                int NumberB = Convert.ToInt32(number1);
                Console.WriteLine("");
                Console.WriteLine("============");
                Console.WriteLine("ANSWER");
                Console.WriteLine("============");
                Console.WriteLine(NumberA / NumberB);

                Console.ReadLine();
            }
        }
    }
}
}

所以,任何帮助都表示赞赏:)

1 个答案:

答案 0 :(得分:1)

您的{ }看起来有点不合适:

您应该在{}后添加}

if (fbmi > 40.1)
{
    Console.WriteLine("Extremely Obese");
    Console.ReadLine();
}

然后从最后删除一个。

然后现在布局,您的其他if声明在if的{​​{1}}声明中。