Here is my simple and newbie program written in C#. I have just tried it for integers but when I tried to input naturally it throws an execption. I wonder how to warn user if any string input occurs without throwing the exception. ( PS: I am an absoulute beginner).
float quiz, mid, final,avg;
Console.WriteLine("Enter quiz score:");
quiz= float.Parse(Console.ReadLine());
Console.WriteLine("Enter mid-term score:");
mid = float.Parse(Console.ReadLine());
Console.WriteLine("Enter final score:");
final = float.Parse(Console.ReadLine());
avg=(quiz+mid+final)/3;
while (avg<=100 && quiz<=100&& mid <=100 && final<=100 )
{
if (avg >= 90)
Console.WriteLine("Grade A");
else if (avg >= 70 && avg < 90)
Console.WriteLine("Grade B");
else if (avg >= 50 && avg < 70)
Console.WriteLine("Grade C");
else if (avg < 50)
Console.WriteLine("Grade F");
else
Console.Write("invalid operation!!");
break;
}
while (avg > 100)
{
Console.WriteLine("Please enter the right scores!");
//Console.ReadLine();
break;
}
while (mid > 100)
{
Console.WriteLine("Please enter the right scores!");
//Console.ReadLine();
break;
}
while (final > 100)
{
Console.WriteLine("Please enter the right scores!");
//Console.ReadLine();
break;
}
while (quiz > 100)
{
Console.WriteLine("Please enter the right scores!");
//Console.ReadLine();
break;
}
Console.ReadLine();