107 325
Assignments Done
98.9%
Successfully Done
In March 2023

# Answer to Question #204264 in C# for Nkhululeko Chabala

Question #204264

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-06-08T10:58:46-0400
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;
}

}
}

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