dimanche 26 mai 2019

Do-While won't repeat itself

I need the user to enter their age, then the program has to calculate how much money they is going to have when their age hit pension. The person is saving 500 or 1000 depending on the situation.

My code won't repeat the if and else statement even though I wrote a Do-While loop. Am I supposed to use a bool-statement? How or where? Or there something else I need to look at?

I've tried using only 'while' but I think I need to use a do-while.

        {
        Console.Write("Enter age");
        string str = Console.ReadLine();
        int MyAge = Convert.ToInt32(str);
        int money = 15000;
        {

            do
            {
                {

                 if (money > 20000 || MyAge < 60)
                    {
                        Console.Write("You are saving little");
                        money = money + 500;
                    }


                else
                     {
                    Console.Write("You are saving a lot");
                    money = money + 1000;
                    }

                    MyAge++;
                }
            }
            while (money > 20000 && MyAge > 65);

        }
        Console.Write("You are retired by the age of " + MyAge + " and you saved " + money + " dollars.");
    }

I expected the program to hit at least 65 but it ends by the age of 26 of I type down that I'm 25 years old. So it doesn't loop.

Aucun commentaire:

Enregistrer un commentaire