I am new to C# and am having trouble with some code that I am writing. Below is the code. I want the user to be able to enter a number between 10 and 50. Once the user does this, I want it to evaluate to Acceptable if it is within the range and Unacceptable if it is not. I have written the code for this in the CheckRange method.
Can anyone tell me what I am doing wrong?
Thanks.
static void Main()
{
bool choice = true;
char character = ' ';
int number = 0;
string validInput;
DisplayInfo();
while (choice)
{
number = PromptForInput(ref character);
validInput = CheckRange(number);
choice = GetInput();
}//End of while loop
}// End of Main
static void DisplayInfo()
{
Console.WriteLine("*** *** *** *** *** *** *** *** *** *** *** ***");
Console.WriteLine("*** This program anables you to enter as ***");
Console.WriteLine("*** many values as you wish....Between the ***");
Console.WriteLine("*** range of 10 and 50. ***");
Console.WriteLine("*** *** *** *** *** *** *** *** *** *** *** ***");
Console.WriteLine();
//Console.Read();
}// End of DisplayInfo
static bool GetInput()
{
char input;
bool choice;
Console.Write("\nWould you like to enter another value?" +
"\nPlease enter y for yes or any other letter for no:");
input = char.Parse(Console.ReadLine());
Console.WriteLine();
switch (input)
{
case 'y':
case 'Y': choice = true;
break;
default: choice = false;
break;
}
return choice;
}//end of GetInput
public static int PromptForInput(ref char character)
{
string input = " 1 ";
int number;
Console.Write("Please enter a value between the range of 10 and 50: ");
Console.WriteLine("Value entered: " + Console.ReadLine() + " - " );
number = int.Parse(input);
return number;
}// End of PromptforInput
static string CheckRange(int inValue)
{
//bool validInput;
if (inValue < 10 || inValue > 50)
return "UnAcceptable";
else
return "Acceptable";
}//End of CheckRange
}// End of class
}//End of namespace