Modify the following program to check for reasonable inputs (or reject un-reasonable ones). For example, a negative GPA or test score, or a GPA of 10 or a test score of more than 100.
using System;
namespace Admit
{
class Program
{
public static void Main(string[] args)
{
float avg;
int score;
Console.WriteLine("Grade point average: ");
avg = float.Parse(Console.ReadLine(), System.Globalization.CultureInfo.InvariantCulture); //decimal mark is "."
Console.WriteLine("Admission test score: ");
score = int.Parse(Console.ReadLine());
if ((avg >= 3) && (score >= 60) || (avg < 3) && (score >= 80))
Console.Write("Accept");
else
Console.Write("Reject");
Console.ReadKey(true);
}
}
}
using System;
namespace Admit
{
class Program
{
public static void Main(string[] args)
{
float avg = float.MinValue;
int score = int.MinValue;
while (avg < 0 || avg >= 10)
{
Console.WriteLine("Grade point average: ");
avg = float.Parse(Console.ReadLine(), System.Globalization.CultureInfo.InvariantCulture); //decimal mark is "."
if(avg < 0 || avg >= 10)
Console.WriteLine("Incorrect input");
}
while(score < 0 || score > 100)
{
Console.WriteLine("Admission test score: ");
score = int.Parse(Console.ReadLine());
if (score < 0 || score > 100)
Console.WriteLine("Incorrect input");
}
if ((avg >= 3) && (score >= 60) || (avg < 3) && (score >= 80))
Console.Write("Accept");
else
Console.Write("Reject");
Console.ReadKey(true);
}
}
}
Comments
Leave a comment