0

So my program is meant to run infinite times until the user enters -999. With this current set up all that happens when any number is entered is it spews out all the text and ignores whatever is entered.

    static void Main(string[] args)
    {
        //Local Variable Declaration//

        const double rate1 = 10;
        const double rate2 = 3;
        const double maxCharge = 50;
        double charge;
        int hoursRented;


        while (true)
        {
            Console.WriteLine("Enter number of hours (-999 to quit) : ");
            hoursRented = Console.Read();
            if (hoursRented == -999)
                break;

            else

                if (hoursRented <= 3)
            {
                charge = hoursRented * rate1;
            }
            else
            {
                charge = (3 * rate1) + ((hoursRented - 3) * rate2);
            }

            if (charge > maxCharge)
            {
                charge = maxCharge;
            }

            Console.WriteLine("Are you a member? (Y/N) : ");
            string memberStatus = Console.ReadLine();
            string upperstring = memberStatus.ToUpper();
            if (memberStatus.Equals("Y"))
            {
                charge = charge - (charge * 1 / 10);
            }

            double TotalCharge = +charge;

            Console.WriteLine("Customer Charge : {0}   Total Charge To Date {1} :  ", charge, TotalCharge);
        }
    }
}

}

Crizzy K10
  • 13
  • 3

1 Answers1

1

As of the documentation for Console.Read:

Reads the next character from the standard input stream.

The method reads only a single character. To read an entire line, use ReadLine instead:

int hours;
if(int.TryParse(Console.ReadLine(), out hours) && hours == -999)
    break;       
MakePeaceGreatAgain
  • 35,491
  • 6
  • 60
  • 111