// declare variables
int inpMark;
string lastName;
char grade = MarkToGrade;
// 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();
question is to use the method to convert the mark into a letter grade
using System;
namespace Questions
{
class Program
{
static char MarkToGrade(int studentMark)
{
if (studentMark >= 90 && studentMark <= 100)
return 'A';
if (studentMark >= 80 && studentMark < 90)
return 'B';
if (studentMark >= 70 && studentMark < 80)
return 'C';
if (studentMark >= 60 && studentMark < 70)
return 'D';
if (studentMark >= 50 && studentMark < 60)
return 'E';
return 'F';
}
static void Main()
{
// declare variables
int inpMark;
string lastName;
// 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);
char grade = MarkToGrade(inpMark);
Console.WriteLine();
Console.WriteLine("Lastname: " + lastName);
Console.WriteLine("Grade: " + grade);
Console.WriteLine();
Console.ReadKey();
}
}
}
Comments
Leave a comment