Answer to Question #326999 in C# for Surprise

Question #326999

Task 4 

Write a program that does the following for 15 

students:

 Reads in 3 marks for each student (you 

need to ensure that only valid marks 

between 0 and 100 are processed) – your 

prompt message to the user should 

indicate which number is being requested 

(see example image of output)

 Calculates and displays the highest mark 

for each student.

Finds and displays the highest mark in the class.


1
Expert's answer
2022-04-11T02:07:27-0400
using System;

namespace students_mark
{
    class Program
    {
        public static void Main(string[] args)
        {
            int i, j, high_m_stud, high_m_class;
            int n_stud = 15;
            int[,] marks = new int[n_stud,3];
            
            Console.WriteLine("Enter marks for 15 students:");
            for (i = 0; i<n_stud; i++)
                for (j=0; j<3; j++)
                {
                    Console.Write("Input mark {0} for student {1}: ", j+1, i+1);
                    marks[i,j]=Convert.ToInt32(Console.ReadLine());
                    while ((marks[i,j]<0) || (marks[i,j]>100))
                    {
                        Console.WriteLine();
                        Console.Write("Mark is invalid. Valid marks between 0 and 100.\nPlease re-input mark: ");
                        marks[i,j]=Convert.ToInt32(Console.ReadLine());
                    }
                }
                
            Console.WriteLine();
            high_m_class = marks[0,0];
            for (i = 0; i<n_stud; i++)
            {
                high_m_stud = marks[i,0];
                for (j = 0; j<3; j++)
                {
                    if (high_m_stud < marks[i,j])
                        high_m_stud = marks[i,j];                        
                    if (high_m_class < marks[i,j])
                        high_m_class = marks[i,j];                        
                }
                Console.WriteLine("Student {0} highest mark: {1}", i+1, high_m_stud);
            }
            Console.WriteLine("Highest mark in the class: {0}", high_m_class);
            
            Console.Write("\nPress any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS