我是c#的初学者,我无法获得以下代码的输出。有人请帮帮我。运行代码时,结果未显示。我确定这里所犯的错误是非常愚蠢的,但我无法识别它。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test2
{
class Program
{
static void Main(string[] args)
{
float num, result;
int opt;
Console.Write("\t Enter your salary:");
num = float.Parse(Console.ReadLine());
Console.Write("\t Enter your option:");
opt = Convert.ToInt32(Console.ReadLine());
switch (opt)
{
case 1:
result = num * (5 / 100);
Console.Write("\t You have to pay the tax of rupees: {0}", result);
break;
case 2:
result = num * (8 / 100);
Console.Write("\t You have to pay the tax of rupees: {0}", result);
break;
case 3:
result = num * (5 / 100);
Console.Write("\t You have to pay the tax of rupees: {0}", result);
break;
default:
Console.WriteLine("Invalid Option...Please try again.");
break;
}
Console.ReadLine();
}
}
}
答案 0 :(得分:0)
尝试下面的代码,它的所有关于括号只是改变序列,你将得到我在VS 2012中尝试过的输出: -
float num, result;
int opt;
Console.Write("\t Enter your salary:");
num = float.Parse(Console.ReadLine());
Console.Write("\t Enter your option:");
opt = Convert.ToInt32(Console.ReadLine());
switch (opt)
{
case 1:
result = (num * 5) / 100;
Console.Write("\t You have to pay the tax of rupees: {0}", result);
break;
case 2:
result = (num * 8) / 100;
Console.Write("\t You have to pay the tax of rupees: {0}", result);
break;
case 3:
result = (num * 5) / 100;
Console.Write("\t You have to pay the tax of rupees: {0}", result);
break;
default:
Console.WriteLine("Invalid Option...Please try again.");
break;
}
Console.ReadLine();
要了解更多信息,请执行以下操作: - http://www.homeandlearn.co.uk/csharp/csharp_s2p13.html