Write a program in C# to show percentage of class attended and Is student is allowed to sit in exam or not.
using System;
using System.Collections.Generic;
using System.Globalization;
namespace App
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter total number of students: ");
int students = int.Parse(Console.ReadLine());
int studentsAttended = 0;
for (int i = 0; i < students; i++)
{
Console.Write("Is the student {0} attended? (1 - yes, 2 - no): ", (i + 1));
int answer = int.Parse(Console.ReadLine());
if (answer == 1)
{
studentsAttended++;
Console.WriteLine("The student is allowed to sit in exam");
}
else {
Console.WriteLine("The student is NOT allowed to sit in exam");
}
}
double percentageClassAttended = ((double)studentsAttended / (double)students) * 100.0;
Console.WriteLine("\n\nPercentage of class attended: {0}\n", percentageClassAttended);
Console.ReadLine();
}
}
}
Comments
Leave a comment