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).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Q204264
{
class Program
{
static void Main(string[] args)
{
int[] marks=new int[5];
for (int i = 0; i < 5; i++)
{
marks[i] = getMark();
}
Console.WriteLine("\nSum of the marks: {0}", marks.Sum());
Console.WriteLine("Average of the marks: {0}", ((float)marks.Sum() / marks.Length));
Console.WriteLine("The number of pass marks entered: {0}", isPass(marks));
Console.ReadLine();
}
static int getMark()
{
int m = -1;
while (m < 0 || m > 100)
{
Console.Write("Enter the mark [0-100]: ");
if (!int.TryParse(Console.ReadLine(), out m))
{
m = -1;
}
}
return m;
}
static int isPass(int[] marks)
{
int passesCounter = 0;
for (int i = 0; i < marks.Length; i++)
{
if (marks[i] >= 60)
{
passesCounter++;
}
}
return passesCounter;
}
}
}
Comments
Leave a comment