0

所以我最近做了一个计算器作为我的 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();
            }
        }
    }
}
}

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

4

1 回答 1

1

看起来你{ }有点不合适:

您应该在}后面添加:

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

然后从最后删除一个。

然后按照现在的布局方式,您的其他if陈述在 for 的if陈述中BMI

于 2013-10-01T17:26:49.777 回答