我正在使用 Visual Studio 在 C# 中编写一个小型控制台应用程序。
我想写两个小程序,都将通过控制台输入六个整数,然后 if 语句将比较所有六个值,最终结果将是控制台输出打印输入的六个值以及从最高到最低的顺序值. 我绞尽脑汁想弄清楚如何做到这一点。
完成此操作后,我将编写第二个程序来使用我认为会更整洁的列表来执行此操作。
所以我认为应该有六个整数来保存输入的值,然后是六个整数来保存有序值,中间的 if 语句可以计算出从最高到最低的顺序。
我试图做嵌套的 if,但它变得很乱,我决定放弃它并重新开始。
我将不胜感激。
这是我正在编写的代码:
int one;
int two;
int three;
int four;
int five;
int six;
int firsthighest;
int secondhighest;
int thirdhighest;
int fourthhighest;
int fifthhighest;
int sixthhighest;
Console.WriteLine("Enter a value");
one = int.Parse(Console.ReadLine());
Console.WriteLine("Enter a value");
two = int.Parse(Console.ReadLine());
Console.WriteLine("Enter a value");
three = int.Parse(Console.ReadLine());
Console.WriteLine("Enter a value");
four = int.Parse(Console.ReadLine());
Console.WriteLine("Enter a value");
five = int.Parse(Console.ReadLine());
Console.WriteLine("Enter a value");
six = int.Parse(Console.ReadLine());
if (one > two)
{
if (one > three)
{
if (one > four)
{
if (one > five)
{
if (one > six)
{
firsthighest = one;
}
}
}
}
}
else if (two > three)
{
if (two > four)
{
if (two > five)
{
if (two > six)
{
firsthighest = two;
}
}
}
}
else if (three > four)
{
if (three > five)
{
if (three > six)
{
firsthighest = three;
}
}
}