我得到命令提示符,以获得错误分数的正确答案,但如果我尝试输入一个好成绩(800)它什么都不做。任何帮助将不胜感激。我是新手,所以我道歉,我的编码器并不漂亮。
//variables
string firstName, lastName, grades = "";
double points = 0, percent = 0;
//Greeting
Console.WriteLine("The purpose of this program is to allow the teacher to calculate the percentage and final grade for students in their class.");
//Display and Inputs
Console.WriteLine("\n\nPlease enter the students first name.");
firstName = Console.ReadLine();
Console.WriteLine("\n\nPlease enter the students last name.");
lastName = Console.ReadLine();
Console.WriteLine("\n\nPlease enter the points that the student received.\n\n");
points = Convert.ToDouble(Console.ReadLine());
//Display after points are entered
if (points < 0 || points > 1000 )
{
Console.WriteLine("Bad Score!");
}
else
{
percent = points / 1000;
if (percent >= .9)
{
grades = "A";
}
else if (percent >= .8)
{
grades = "B";
}
if (percent >= .7)
{
grades = "C";
}
else if (percent >= .6)
{
grades = "D";
}
if (percent >= .0)
{
grades = "F";
}
else
{
Console.WriteLine("WRONG!!");
}
}
grades = Console.ReadLine();
//Outputs
Console.WriteLine(firstName);
Console.WriteLine(lastName);
Console.WriteLine(points);
Console.WriteLine(percent.ToString("P"));
Console.WriteLine("so they made an" + grades);
//Closing statement
Console.WriteLine("Goodbye");
Environment.Exit(1);
}
}
}
答案 0 :(得分:1)
名字 - 普尼特 姓氏 - Chawla 输入学生收到的积分 - 800 10
然后回答是
普尼特 乔拉 800 80.00% 所以他们做了10 再见
如果(条件&lt; 0 || points> 1000)这个条件为假,那么你按照我认为的百分比给出成绩,你不需要再次从用户那里获得成绩。
在某些情况下,由于您已设置,因此输出错误 错了 - if,elseif,if,elseif,if then else 正确 - if,elseif,elseif,elseif,elseif then else。
答案 1 :(得分:0)
您正在使grades
变量正确无误。但是在ifs语句结束时,你要覆盖它的值,所以只需删除这一行:
grades = Console.ReadLine();
PS:您也可以使用if
else if
语句
答案 2 :(得分:0)
你有很多问题
在&#39; C&#39;之前,您错过了else
。和&#39; F&#39;分支机构。目前,所有正面评分都将成为&#39; F&#39>
else if (percent >= .7)
{
grades = "C";
}
再次
else if (percent >= .0)
{
grades = "F";
}
grades = Console.ReadLine();
我相信你可能有意:
Console.WriteLine(grades);
Console.ReadLine
或类似的defmacro
以允许用户查看结果答案 3 :(得分:0)
乍一看你的pgms有两个问题
if..else
else
内的else
{
percent = points / 1000;
if (percent >= .9)
{
grades = "A";
}
else if (percent >= .8)
{
grades = "B";
}
else if (percent >= .7)
{
grades = "C";
}
else if (percent >= .6)
{
grades = "D";
}
else if (percent >= .0)
{
grades = "F";
}
else
{
Console.WriteLine("WRONG!!");
}
}
错误应该是
grade = Consolde.ReadLine();
在检查百分比&gt; = 0.7和百分比&gt; =。0时,您是否缺少其他信息 假设您输入800,因此百分比将为0.8,因此百分比&gt; =。08的条件为真,等级=“B”,因为没有其他百分比&gt; = 0.7它也将通过,等级将变为“ c“在检查百分比&gt; = .0时没有别的,所以它也会通过,等级将变为”F“,所以在所有条件下都需要。所以最后有什么积极的百分比是等级将是“F”因为缺少其他......在if条件
contains()
,因为它会覆盖您的成绩。