Question

This C# program prints out a corresponding letter grade for a given mark. It uses a...

This C# program prints out a corresponding letter grade for a given mark. It uses a method (called MarktoGrade) to determine the letter grade. MarktoGrade takes one integer call by value formal parameter (called mark) and returns a char value that is the letter grade. All of the input and output (except an error message) is done in Main. There is one syntax error in this program that you will need to fix before it will compile (the error is in the line where the method is called).

using System;
public static class Lab3_1
{
    public static void Main()
    {
        // declare variables
        int inpMark;
        string lastName;
        char grade = ' '; 
 
        // enter the student's last name
        Console.Write("Enter the last name of the student => ");
        lastName = Console.ReadLine();
        // enter (and validate) the mark
        do {
            Console.Write("Enter a mark between 0 and 100 => ");
            inpMark = Convert.ToInt32(Console.ReadLine());
        } while (inpMark < 0 || inpMark > 100);

        // Use the method to convert the mark into a letter grade
        grade = MarkToGrade();

        // print out the results
        Console.WriteLine("{0}'s mark of {1} converts to a {2}", lastName,
                 inpMark, grade);
        Console.ReadLine();
    }

    // Method: MarkToGrade
    // Parameter
    //      mark: call by value parameter to be converted to a letter grade
    // Returns: the corresponding letter grade
    public static char MarkToGrade(int mark)
    {
        char letterValue;

        // multi-alternative If statement to determine letter grade
        if(mark > 0 && mark < 50)
            letterValue = 'F';
        else if(mark >= 50 && mark < 60)
            letterValue = 'D';
        else if(mark >= 60 && mark < 75)
            letterValue = 'C';
        else if(mark >= 75 && mark < 85)
            letterValue = 'B';
        else if(mark >= 85 && mark <= 100)
            letterValue = 'A';
        else 
        {
            Console.WriteLine("***Error - invalid mark");
            letterValue = 'X';
        }
        
        //return the letter grade back to Main 
        return letterValue;
    }
}

Run the program using input Smith and 98

What is the syntax error and how did you fix it?

What is the output?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer

 grade = MarkToGrade(); here is the error MarkToGrade take one int argument and here there is no argument.
using System;
public static class Lab3_1
{
    public static void Main()
    {
        // declare variables
        int inpMark;
        string lastName;
        char grade = ' '; 
 
        // enter the student's last name
        Console.Write("Enter the last name of the student => ");
        lastName = Console.ReadLine();
        // enter (and validate) the mark
        do {
            Console.Write("Enter a mark between 0 and 100 => ");
            inpMark = Convert.ToInt32(Console.ReadLine());
        } while (inpMark < 0 || inpMark > 100);

        // Use the method to convert the mark into a letter grade
        grade = MarkToGrade(inpMark);

        // print out the results
        Console.WriteLine("{0}'s mark of {1} converts to a {2}", lastName,
                 inpMark, grade);
        Console.ReadLine();
    }

    // Method: MarkToGrade
    // Parameter
    //      mark: call by value parameter to be converted to a letter grade
    // Returns: the corresponding letter grade
    public static char MarkToGrade(int mark)
    {
        char letterValue;

        // multi-alternative If statement to determine letter grade
        if(mark > 0 && mark < 50)
            letterValue = 'F';
        else if(mark >= 50 && mark < 60)
            letterValue = 'D';
        else if(mark >= 60 && mark < 75)
            letterValue = 'C';
        else if(mark >= 75 && mark < 85)
            letterValue = 'B';
        else if(mark >= 85 && mark <= 100)
            letterValue = 'A';
        else 
        {
            Console.WriteLine("***Error - invalid mark");
            letterValue = 'X';
        }
        
        //return the letter grade back to Main 
        return letterValue;
    }
}

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
This C# program prints out a corresponding letter grade for a given mark. It uses a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For the following C# program: Let’s add one more user defined method to the program. This...

    For the following C# program: Let’s add one more user defined method to the program. This method, called ReverseDump is to output the values in the array in revere order (please note that you are NOT to use the Array.Reverse method from the Array class). The approach is quite simple: your ReverseDump method will look very similar to the Dump method with the exception that the for loop will count backwards from num 1 to 0 . The method header...

  • ASSIGNMENT #3 ** using System; namespace GradeCalculatorNew {    class MainClass    {        public...

    ASSIGNMENT #3 ** using System; namespace GradeCalculatorNew {    class MainClass    {        public static void Main (string[] args)        {            int test1,test2,test3;            double average,average2;            char letterGrade;            Console.WriteLine("Enter test score1");            test1=Convert.ToInt32(Console.ReadLine());            Console.WriteLine("Enter test score2");            test2=Convert.ToInt32(Console.ReadLine());            Console.WriteLine("Enter test score3");            test3=Convert.ToInt32(Console.ReadLine());            average=(test1+test2+test3)/3.0;            average=(int)(average+0.5);           ...

  • Below is a java program that inputs an integer grade and turns it into a letter...

    Below is a java program that inputs an integer grade and turns it into a letter grade. Update the below java code as follows and comment each line to explain what is happening: 1. Convert the if-else-if code block to a switch statement to solve the problem. 2. Use modulus to convert the grade input so that the range of grades are converted to one value. (comment the line) import java.util.Scanner; public class GradeLetterTest { public static void main(String[] args)...

  • Hello in C#. I need help understanding and knwoing what i missed in my program. The...

    Hello in C#. I need help understanding and knwoing what i missed in my program. The issue is, the program is supposed to have user input for 12 family members and at the end of the 12 it asks for user to input a name to search for. When i put a correct name, it always gives me a relative not found message. WHat did i miss. And can you adjust the new code so im able to see where...

  • Complete the program, Grade.java, below. The program takes in a student's score and prints the corresponding...

    Complete the program, Grade.java, below. The program takes in a student's score and prints the corresponding letter grade assuming a standard 60-70-80-90 scale for cutoff of each grade. For example, if a student's score is 52.6 they would be assigned an "F" grade. If a student's score is 87.8 they would be assigned a "B grade. The program should take in the score as a double value and print the letter grade (capitalized letter of A, B, C, D, or...

  • What I need: Write a program named Averages that includes a method named Average that accepts...

    What I need: Write a program named Averages that includes a method named Average that accepts any number of numeric parameters, displays them, and displays their average. For example, if 7 and 4 were passed to the method, the ouput would be: 7 4 -- Average is 5.5 Test your function in your Main(). Tests will be run against Average() to determine that it works correctly when passed one, two, or three numbers, or an array of numbers. What I...

  • C#, I am getting error placing them all in one file pls set them in the...

    C#, I am getting error placing them all in one file pls set them in the order that all 3 work in one file. Thanks //Program 1 using System; class MatrixLibrary { public static int[,] Matrix_Multi(int[,] a, int [,]b){ int r1= a.GetLength(0); int c1 = a.GetLength(1); int c2 = b.GetLength(1); int r2 = b.GetLength(0); if(r2 != c2){ Console.WriteLine("Matrices cannot be multiplied together.\n"); return null;    }else { int[,] c = new int[r1, c2]; for (int i = 0; i <...

  • i need help fixing my code. here is the assignment: Make a class that contains the...

    i need help fixing my code. here is the assignment: Make a class that contains the following functions: isLong, isDouble, stringToLong, and stringToDouble. Each receives a string and returns the appropriate type (bool, bool, long, and double).During the rest of the semester you will paste this class into your programs and will no longer use any of the "standard" c# functions to convert strings to numbers. here is my code. it works for the long method but not the double:...

  • Test Scores and Grade Write a program that has variables to hold three test scores. The...

    Test Scores and Grade Write a program that has variables to hold three test scores. The program should ask the user to enter three test scores and then assign the values entered to the variables. The program should display the average of the test scores and the letter grade that is assigned for the test score average. Use the grading scheme in the following table: Test Score Average Letter Grade 90–100 A 80–89 B 70–79 C 60–69 D Below 60...

  • C# Arrays pne and Look at the code below Notice that the program has one class...

    C# Arrays pne and Look at the code below Notice that the program has one class called Tournament. . It defines an integer array called scores to hold all the scores in the tournament .The constructor for the class then actually creates the array of the required size. class Tournament int[ ] scores; const int MAX = 6; // define scores as an integer array // set a constant size public static void Main() //program starts executing here Tournament myTournament...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT