C# 写一个程序,计算五次考试的平均分数
我正在做作业。英语不是我的第一语言,所以我很困惑 问题是:编写一个程序,计算五个考试分数的平均值。声明并使用五个检查值执行编译时初始化。为检查值声明整数内存位置。使用整数常量定义分数数。打印所有分数。平均值的格式应为小数点右侧的两位数字。使用不同的值重新运行应用程序。一定要对结果进行桌面检查 我不确定编译时初始化是什么意思?什么是为检查值声明整数内存位置。要我做什么?桌面检查是什么意思 这是我的c代码:C# 写一个程序,计算五次考试的平均分数,c#,C#,我正在做作业。英语不是我的第一语言,所以我很困惑 问题是:编写一个程序,计算五个考试分数的平均值。声明并使用五个检查值执行编译时初始化。为检查值声明整数内存位置。使用整数常量定义分数数。打印所有分数。平均值的格式应为小数点右侧的两位数字。使用不同的值重新运行应用程序。一定要对结果进行桌面检查 我不确定编译时初始化是什么意思?什么是为检查值声明整数内存位置。要我做什么?桌面检查是什么意思 这是我的c代码: using System; using static System.Console; na
using System;
using static System.Console;
namespace Chap2_1
{
class Chap2_1
{
static void Main()
{
int score1;
int score2;
int score3;
int score4;
int score5;
double average;
Console.Write("Please enter the 1st score: ");
score1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter the 2nd score: ");
score2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter the 3rd score: ");
score3 = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter the 4th score: ");
score4 = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter the 5th score: ");
score5 = Convert.ToInt32(Console.ReadLine());
average = (score1+score2+score3+score4+score5) /5;
Console.Write("Average score is " + "{0:N2}", average);
Console.ReadKey();
}
}
}
这些不应该是你老师的问题吗?你的老师将了解你的奋斗历程,能够比我们任何人都更好地帮助你,这仅仅是因为他/她在你的学习中所扮演的角色 也就是说,编译时初始化类似于:
int[] scores = new int[] { 100,80,90,64,72 };
或:
至于内存位置,我建议您阅读Microsoft的C编程指南:
哦,桌面检查意味着用笔和纸手动进行相同的计算,以验证您得到的结果是否与代码相同
我不确定编译时初始化是什么意思
这意味着您的分数应该从硬编码开始在代码中设置一个值,而不是由用户输入设置的值或在程序运行后由程序计算出来的值
换言之,替换为:
Console.Write("Please enter the 1st score: ");
score1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter the 2nd score: ");
score2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter the 3rd score: ");
score3 = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter the 4th score: ");
score4 = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter the 5th score: ");
score5 = Convert.ToInt32(Console.ReadLine());
比如说:
//Replace the pointed numbers with whatever the scores should be.
// ||
// vv
score1 = 11;
score2 = 22;
score3 = 33;
score4 = 44;
score5 = 55;
什么是为检查值声明整数内存位置
这意味着声明负责保存分数的变量,以便对其进行平均。换言之,本部分:
int score1;
int score2;
int score3;
int score4;
int score5;
桌面检查是什么意思
这意味着你应该用钢笔和纸平均分数,并确保你的程序输出的结果是正确的
附言:我不想粗鲁,但这个社区是为关于代码的问题而建立的。如果你不懂这个问题,或者不懂英语,你应该问你的老师
我们在这里帮助您编程。。。不需要翻译或口译。不要像以前那样从控制台读取中的值,用代码初始化分数。我认为这意味着你应该硬编码你的值,而不是从控制台获取。为什么要否决?也不知道,但别担心,同时我用+1来平衡它=谢谢你,先生!:
int score1;
int score2;
int score3;
int score4;
int score5;