In: Computer Science
C# PLEASE
Lab7B: For this lab, you’re going to write a program that prompts the user for the number of GPAs to enter. The program should then prompt the user to enter the specified number of GPAs. Finally, the program should print out the graduation standing of the students based on their GPAs. Your program should behave like the sample output below.
Sample #1:
Enter the number of GPAs: 5
GPA #0: 3.97
GPA #1: 3.5
GPA #2: 3.499
GPA #3: 3.71
GPA #4: 1.9
Student #0: Summa Pum Laude
Student #1: Pum Laude
Student #2: Graduating
Student #3: Magna Pum Laude
Student #4: Not graduating
Sample #2:
Enter the number of GPAs: 7
GPA #0: 0.03 GPA #1: 4.0
GPA #2: 3.32 GPA #3: 2.81
GPA #4: 3.75 GPA #5: 3.85
GPA #6: 2.3
Student #0: Not graduating
Student #1: Summa Pum Laude
Student #2: Graduating
Student #3: Graduating
Student #4: Magna Pum Laude
Student #5: Magna Pum Laude
Student #6: Graduating
Explanation:
here is the code which asks for the number of GPAs and then the value of the GPAs.
After that, according to the values, it prints the result for each student.
Code:
using System;
class HelloWorld {
static void Main() {
Console.Write("Enter the number of GPAs: ");
int n = Convert.ToInt32(Console.ReadLine());
double[] a = new double[n];
for(int i=0; i<n; i++)
{
Console.Write("GPA #"+(i)+": ");
a[i] = Convert.ToDouble(Console.ReadLine());
}
for(int i=0; i<n; i++)
{
Console.Write("Student #"+(i)+": ");
if(a[i]<2)
Console.WriteLine("Not graduating");
else if(a[i]<3.5)
Console.WriteLine("Graduating");
else if(a[i]==3.5)
Console.WriteLine("Pum Laude");
else if(a[i]<3.9)
Console.WriteLine("Magna Pum Laude");
else
Console.WriteLine("Summa Pum Laude");
}
}
}
output:
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!