所以我有这段代码,我知道由于作用域(最有可能)而无法正常工作,但是由于即时通讯是使用c#的新手,所以我不能肯定地说,所以我想知道为什么我不能做到这一点结束对这种情况的最佳解决(最好仅使用if语句)。
我要做的一件事是在每个if内执行Console.WriteLine(),但看起来一点也不干净,还尝试将变量定义为任意值以供以后更改,而不是仅仅清除它们而已工作,但我真的不知道为什么
Console.Write("please enter a number en i will tell you the day of the
week\n and how many push ups you need to do\n and how many calories you
lost");
int num = Convert.ToInt32(Console.ReadLine());
string day;
int push;
const int cal = 5;
if (num == 1)
{
day = "sunday";
push = 10;
}
else if (num == 2)
{
day = "monday";
push = 15;
}
else {
Console.WriteLine("your number is out of range");
}
Console.WriteLine("your day is {0} and you need to do {1} push ups
to lose {2} calories", day, push, push * cal);
我认为las cw总结了我想通过这个简单的练习问题做的事情