Answer to Question #199413 in C# for Nkhululeko Chabala

Question #199413

Write a program that reads in 5 marks. Your program must use the getMark method to ensure that valid marks are processed. You need to calculate the sum and the average of the marks. Your program must also use the isPass method to determine the number of pass marks entered. When the 5 marks have been processed you need to display the sum, average and number of passes (from these marks).


1
Expert's answer
2021-05-28T10:31:42-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace Q199413{
    class Program
    {
        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {


            int numberPasses = 0;
            int sum=0;
            for (int m = 0; m < 5; m++) {
                //get mark from the user
                int mark = getMark();
                //Check if mark is pass
                if (isPass(mark)) {
                    numberPasses++;
                }
                sum+=mark;
            }
            //Display sum
            Console.WriteLine("Sum {0}",sum);
            //Display Average
            Console.WriteLine("Average {0}", ((float)sum/5.0));
            //Display the number of passes marks
            Console.WriteLine("The number of passes marks {0}", numberPasses);


            Console.ReadLine();
        }
        /// <summary>
        /// This function allows to read mark from the keyboard
        /// </summary>
        /// <returns></returns>
        static int getMark() {
            int mark =-1;
            while (mark < 0 || mark>100)
            {
                Console.Write("Enter the mark: ");
                if(!int.TryParse(Console.ReadLine(), out mark)){
                    mark=-1;
                }
            }
            return mark;
        }
        /// <summary>
        /// This function allows to determine the number of pass marks entered. 
        /// </summary>
        /// <param name="mark"></param>
        /// <returns></returns>
        static bool isPass(int mark)
        {
            if (mark < 60) {
                return false;
            }
            return 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
APPROVED BY CLIENTS