-3

I have code that accepts a user's name and marks for subjects. I want to display the courses, marks and grades in a table structure but the data is not being displayed.

Can you please explain how to put the data in a table format eg: {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();










    }
}
}
Tony
  • 9,672
  • 3
  • 47
  • 75
  • 1
    Your writeline formats are wrong. Use this : Console.WriteLine("{0,6}|{1,13}|{2,13}|", csharp, A, A * CHours);. The formats first in one set of double quotes then the variables. – jdweng Dec 17 '15 at 23:02

2 Answers2

3

You are calling the wrong overload of WriteLine to use the formating features, you want the one where you pass the format as the first parameter and everything after it are the values.

For example, you would change this line:

Console.WriteLine("|", csharp,  "|{0,6}        |{1,13}|{2,13}|", A, A * CHours,  "|");

To Something like this:

Console.WriteLine("|{0}|{1,6}|{2,13}|", csharp, A, A * CHours);

Also, if you have problems with the alignment of the table, you may want to look here for the solution.

Community
  • 1
  • 1
Alexandre Borela
  • 1,576
  • 13
  • 21
  • 3
    @arcyqwerty Your edit review is the subject of this meta post: https://meta.stackoverflow.com/questions/312801/reject-edit-only-to-make-same-edit I'd appreciate if you could voice your thoughts as to the reasoning of the action. – Zizouz212 Dec 18 '15 at 03:41
  • His edit made sense, it made the post clearer, it was my mistake to not make the links smaller which is something i normally do but forgot in this case. – Alexandre Borela Dec 18 '15 at 10:38
  • I think @Zizouz212 is talking about my suggested edit, which was rejected yet the question was edited in the way I suggested. – Just Do It Dec 18 '15 at 15:04
  • Oh, ok, i didn't see it, when I answered i got off my PC and when i came back it was already edited. – Alexandre Borela Dec 18 '15 at 16:44
2

The first argument of Console.WriteLine is a format string, the following parameters are arguments that are inserted in the string. Example:

Console.WriteLine("A = {0}, B = {1}, C = {2}", a, b, c);

You can also specify a length and format, e.g.: {1,15:N2}

This means that parameter 1 (which must be of a numeric type) has a length of 15 characters and is formatted with 2 decimals.

You can also use only a length {1,15} or only a format {1:N2}. Use a positive length for a right align and a negative length for a left align.


If you are using Visual Studio 15, you can also use the new string interpolation feature. The same example as above could be written like this:

Console.WriteLine($"A = {a}, B = {b}, C = {c}");

where the variables (and other expressions) can be written directly into the format string.

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188