【发布时间】:2015-08-21 03:15:47
【问题描述】:
您好,我在获取系统生成变量的值时遇到问题。这是从用户那里获取值的代码;
public void DetailsRate()
{
begin1:
Console.WriteLine("\n \t Rate the Acting on a scale of 0 to 5");
RateActing = int.Parse(Console.ReadLine());
switch (RateActing)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
Console.WriteLine("\n you have rated the action of the movie {0}", RateActing);
break;
default:
Console.WriteLine("you have selected the wrong choice {0}", RateActing);
goto begin1;
}
begin2:
Console.WriteLine("\n \t Rate the music of the movie on a scale of 0 to 5");
RateMusic = int.Parse(Console.ReadLine());
switch (RateMusic)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
Console.WriteLine("you have rated the music of the movie {0}", RateMusic);
break;
default:
Console.WriteLine("you have selected the wrong choice {0}", RateMusic);
goto begin2;
}
}
我将输入的值调用到这段代码中
public double getoverallRate(double rateact, double ratemus)
{
double totrate = 0;
rateact = RateActing * 0.25;
ratemus = RateMusic * 0.15;
totrate = (rateact + ratemus);
return totrate;
}
这里是主要方法
static void Main(string[] args)
{
MovieRating MR = new MovieRating();
MR.DetailsRate();
MovieRating MT = new MovieRating();
double totrate = MT.getoverallRate(1, 2);
Console.WriteLine("total rate is {0}", totrate);
Console.ReadKey();
}
请我错过 totrate 的值只是给我 0。请帮助我。
【问题讨论】:
-
getoverallRate 有两个参数,你传递的是 5。它是如何编译的?那是那里著名的“goto”声明吗:o?
-
这应该是一个错误,我没有复制整个参数。它实际上是 5 个参数。我不明白著名的“goto”的含义。
-
你的
DetailRate()呢?MR和MT的用途是什么,为什么不只使用一个而不是两个?RateActing和RateMusic存储在哪里?它们是全局变量吗?很抱歉,您可能需要重写整个程序……遵循 OO 方式。