0

I want to give input range between 0 to 100 in console c#

int eng, tel, hin, mat, sci, soc,j; float total, average; float percentage; Console.WriteLine("MARKS OF THE STUDENT"); Console.Write("Marks in English :"); eng = Convert.ToInt32(Console.ReadLine()); Console.Write("Marks in Telugu :"); tel = Convert.ToInt32(Console.ReadLine()); Console.Write("Marks in Hindi :"); hin = Convert.ToInt32(Console.ReadLine()); Console.Write("Marks in Maths :"); mat = Convert.ToInt32(Console.ReadLine()); Console.Write("Marks in Science :"); sci = Convert.ToInt32(Console.ReadLine()); Console.Write("Marks in Social :"); soc = Convert.ToInt32(Console.ReadLine()); total = eng + tel + hin + mat + sci + soc; average = total / 6; percentage = (total*100)/600; decimal avg1 =

14th Oct 2021, 5:10 PM
Mallikarjuna Sarma
1 Réponse
0
If you want a range between 0 and 100 then after input function you can place simple if statment, that states if input is higher in value than 100, then the value of input is set to 100 and simillar fashion goes for the 0: if the value is less than 0, set the value to 0. Hope that helps (I didn't write any code because I don't know much about C#)
21st Oct 2021, 5:27 AM
Grzegorz Sikorski
Grzegorz Sikorski - avatar