Answer to Question #301565 in C# for Nill

Question #301565

Write a program in C# to show percentage of class attended and Is student is allowed to sit in exam or not.


1
Expert's answer
2022-02-23T06:24:10-0500


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();
        }


    }
}

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