我的代码接受用户的名称和主题标记。我想在表结构中显示课程,标记和成绩,但数据没有显示。
您能否解释一下如何将数据放入表格格式,例如:{1,13}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace End_of_semester_results_assignment
{
class Program
{
static void Main(string[] args)
{
string Name = "Please enter your name";
string NameEntered;
string csharp= "PROGRAMMING USING C#";
string fcs = "FOUNDATIONS OF COMPUTER SCIENCE";
string aw = "ACADEMIC WRITING";
string ist = "INTRODUCTORY STATISTICS";
string frl = "FRENCH";
string adv = "African Development";
double fx;
double mean;
double FTOTAL;
double X;
double OG;
int CHours = 3;
Console.WriteLine(Name);
NameEntered = Console.ReadLine();
Console.Clear();
Console.WriteLine("Welcome To The CWA Calculator.....");
Console.WriteLine("");
Console.WriteLine(" GRADING SYSTEM ");
Console.WriteLine("XXXXXXXXXXXXXXXX");
Console.WriteLine("");
Console.WriteLine(" 70-100 = A ");
Console.WriteLine(" 60-69.9 = B");
Console.WriteLine(" 50-59.9 = C");
Console.WriteLine(" 40-49.9 = D");
Console.WriteLine(" 0-39.9 = F");
Console.WriteLine("");
Console.WriteLine("END OF SEMESTER RESULTS FOR - {0}", NameEntered);
Console.WriteLine("xxxxxxxxxxxxxxxxxxxxxxxxxxx");
Console.WriteLine("");
Console.WriteLine("Course List...");
Console.WriteLine("1)PROGRAMMING USING C#: ");
Console.WriteLine("");
Console.WriteLine("2)FOUNDATIONS OF COMPUTER SCIENCE: ");
Console.WriteLine("");
Console.WriteLine("3)ACADEMIC WRITING: ");
Console.WriteLine("");
Console.WriteLine("4)INTRODUCTORY STATISTICS: ");
Console.WriteLine("");
Console.WriteLine("5)FRENCH: ");
Console.WriteLine("");
Console.WriteLine("6)AFRICAN DEVELOPMENT: ");
Console.WriteLine("");
Console.WriteLine("END OF SEMESTER CWA");
Console.WriteLine("Enter your marks for PROGRAMMING USING C#: ");
Console.WriteLine();
int A = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
Console.WriteLine("Enter your marks For Foundations Of Computer Science: ");
Console.WriteLine();
int B = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
Console.WriteLine("Enter your marks for Academic Writing: ");
Console.WriteLine();
int C = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
Console.WriteLine("Enter your marks for Introductory Statistics: ");
Console.WriteLine();
int D = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
Console.WriteLine("Enter your marks for French(basic): ");
Console.WriteLine();
int E = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
Console.WriteLine("Enter your marks for African Development: ");
Console.WriteLine();
int F = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
fx = A * CHours + B * CHours + C * CHours + D * CHours + E * CHours + F * CHours;
FTOTAL = CHours + CHours + CHours + CHours + CHours + CHours;
mean = fx / FTOTAL;
OG = mean;
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.Black;
Console.WriteLine("|--------------------------------------------------------------|");
Console.WriteLine("|COURSE | MARKS | GRADE | W.MARK |");
Console.WriteLine("|-------------|-------------|-------------|--------------------|");
Console.WriteLine("|", csharp, "|{0,6} |{1,13}|{2,13}|", A, A * CHours, "|");
Console.WriteLine("| | | | |");
Console.WriteLine("|", fcs, "|{0,6} |{1,13}|{2,13}|", B, B * CHours, "|");
Console.WriteLine("| | | | |");
Console.WriteLine("|", aw, "|{0,6} |{1,13}|{2,13}|", C, C * CHours, "|");
Console.WriteLine("| | | | |");
Console.WriteLine("|", frl, "|{0,6} |{1,13}|{2,13}|", D, D * CHours, "|");
Console.WriteLine("| | | | |");
Console.WriteLine("|", ist, "|{0,6} |{1,13}|{2,13}|", E, E * CHours, "|");
Console.WriteLine("| | | | |");
Console.WriteLine("|", adv, "|{0,6} |{1,13}|{2,13}|", F, F * CHours, "|");
Console.WriteLine("| | | | |");
Console.WriteLine("|{2,13}", fx);
Console.WriteLine("|---------- |-------------|-------------| |");
Console.WriteLine("");
Console.WriteLine("To calculate your CWA...");
Console.WriteLine("CWA = W.Marks / Credit Hours");
Console.WriteLine(" CWA = ∑fx", fx);
Console.WriteLine(" ----");
Console.WriteLine(" fx", FTOTAL);
Console.WriteLine("Your CWA is {0}", mean);
Console.WriteLine("");
if (mean >= 70)
{
Console.WriteLine("Overall grade = A");
Console.WriteLine("exceptional work");
Console.WriteLine();
}
else if ((mean <= 69.9) & (mean >= 60))
{
Console.WriteLine("Overall grade = B");
Console.WriteLine("good job");
Console.WriteLine();
}
if ((mean <= 59.9) & (mean >= 50))
{
Console.WriteLine("Overall grade = C");
Console.WriteLine("average");
Console.WriteLine();
}
if ((mean <= 49.9) & (mean >= 40))
{
Console.WriteLine("Overall grade = D");
Console.WriteLine("below average");
Console.WriteLine();
}
if ((mean <= 39.9) & (mean >= 0))
{
Console.WriteLine("Overall grade = F");
Console.WriteLine("fail");
Console.WriteLine();
}
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("Press Any Key To Exit");
Console.WriteLine("");
Console.WriteLine("");
Console.ReadLine();
}
}
}
答案 0 :(得分:3)
您正在调用WriteLine
的错误重载以使用格式化功能,您希望将传递格式的格式作为第一个参数,并且后面的所有内容都是值。
例如,您可以更改此行:
Console.WriteLine("|", csharp, "|{0,6} |{1,13}|{2,13}|", A, A * CHours, "|");
To like like:
Console.WriteLine("|{0}|{1,6}|{2,13}|", csharp, A, A * CHours);
此外,如果您在对齐表时遇到问题,可能需要查看here以获得解决方案。
答案 1 :(得分:2)
Console.WriteLine
的第一个参数是格式字符串,以下参数是插入字符串中的参数。例如:
Console.WriteLine("A = {0}, B = {1}, C = {2}", a, b, c);
您还可以指定长度和格式,例如:{1,15:N2}
这意味着参数1(必须是数字类型)的长度为15个字符,格式为2位小数。
您也可以只使用{1,15}
长度或{1:N2}
格式。使用正长度进行右对齐,使用负长度进行左对齐。
如果您使用的是Visual Studio 15,还可以使用新的字符串插值功能。上面的例子可以写成:
Console.WriteLine($"A = {a}, B = {b}, C = {c}");
其中变量(和其他表达式)可以直接写入格式字符串。