我目前正在做一个树屋培训课程,您可以在其中创建一个健身控制台应用程序,记录您的输入锻炼时间,记录它并根据您的需求提供反馈,并且在树屋社区中没有得到任何帮助,所以如果有人能够帮助我找到以下解决方案,这将是很大的帮助,我不确定它是否与放置变量的位置有关,如果它位于调用in的大括号之间。我不太确定我真的很新
using System;
namespace Treehouse.fitnessFrog
{
class Program
{
static void Main()
{
int runningTotal = 0;
bool keepGoing = true;
while(keepGoing) {
// Prompt user for minutes exercised
Console.Write("Enter how many minutes you exercised or type quit to exit ");
string entry = Console.ReadLine();
if(entry == "quit")
{
keepGoing = false;
}else{
try
{
int minutes = int.Parse(entry);
if(minutes <= 0)
{
Console.WriteLine("Not Acceptable");
continue;
}
else if(minutes <= 10)// Number 1
{
Console.WriteLine("Better than nothing, am I right ?");
}
else if(minutes <= 30) // Number 2
{
Console.WriteLine("You are still quite lazy");
}
else if(minutes <= 60) // Number 3
{
Console.WriteLine("Your doing all right i guess. But work on you're spelling!");
}
else
{
Console.WriteLine("Cool story bro");
}
}
catch(FormatException)
{
Console.WriteLine("That is not valid");
continue;
}
// Add minutes exercised to total
runningTotal = runningTotal + minutes;
// Display total minutes exercised to the screen
Console.WriteLine("You've entered "+ runningTotal + " minutes");
// Repeat until user quits
}
}
Console.WriteLine("Goodbye mate");
}
}
}
答案 0 :(得分:0)
您应该在minutes
块之外声明变量try
:
int minutes = 0; // create variable here
try
{
minutes = int.Parse(entry); // here only use this variable
if(minutes <= 0)
{
// your code
}
//else if statements
...
}