1.Create a console program that will perform the following:
•Ask the user to enter five (5) grades
•Compute the average of the grades
•Round of the average using method of Math class
2. Name the project as ComputeAverageApp and the class as ComputeAverageProgram.
Example output:
Enter 5 grades separated by new Line.
90
83
87
98
93
The average is 90.2 and round off to 90.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputeAverageApp
{
class ComputeAverageProgram
{
static void Main(string[] args)
{
int[] grades = new int[5];
Console.WriteLine("Please, input 5 grades: ");
for (int i = 0; i < 5; i++)
{
grades[i] = Convert.ToInt32(Console.ReadLine());
}
int sum = 0;
double avg = 0;
for (int i = 0; i < 5; i++)
{
sum += grades[i];
}
avg = sum / 5.0;
Console.WriteLine("The average is {0} and round off to {1}.", avg, Math.Round(avg, 0));
Console.ReadKey();
}
}
}
Comments
Leave a comment