0

I want it to add 10 to the current hunger level when they press F and 10 to the current thirst level when they press D. Currently it feeds it automatically without me pressing anything. I know the location of the code is wrong but how should I fix it

using System;

namespace ConsoleApplication1
{

class Program

{

    static void Main(string[] args)

    {

        Console.WriteLine("Enter your name, please: ");

        string name = Console.ReadLine();

        Console.WriteLine("Good choice, " + name);

        Console.Write("Press F to feed yourself(+10) and D to drink some water(+10)");
        Console.WriteLine(" ");
        int hunger = 60;
        int thirst = 60;

        while (hunger < 101)
        while (hunger > 1) 
        while (thirst < 101)
        while (thirst > 1)
                if (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.F))
                        {
                            System.Threading.Thread.Sleep(500);
                            {
                                hunger = hunger + 10;
                                Console.Write("Food: {0:0.0}".PadRight(15), hunger);

                                Console.Write("Water: {0:0.0}".PadRight(70), thirst);
                            }
                        }
                if (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.F))
                        {
                            System.Threading.Thread.Sleep(500);
                            {
                                thirst = thirst + 10;
                                Console.Write("Food: {0:0.0}".PadRight(15), hunger);

                                Console.Write("Water: {0:0.0}".PadRight(70), thirst);
                            }
                        }
        {
            System.Threading.Thread.Sleep(5000);
            Console.Write(" ");
            {
                hunger = hunger - 2;
                thirst = thirst - 4;
                Console.Write("Food: {0:0.0}".PadRight(15), hunger);

                Console.Write("Water: {0:0.0}".PadRight(70), thirst);

            }













        if (thirst < 1)
        {
            Console.Write("You died from dehydration, RIP:" + name);
            System.Threading.Thread.Sleep(3000);
            {
                System.Environment.Exit(1);
            }
        }
        if (thirst > 101)
        {
            Console.Write("You died from drinking too much, RIP:" + name);
            System.Threading.Thread.Sleep(3000);
            {
                System.Environment.Exit(1);
            }
        }
        }
        if (hunger < 1)
        {
            Console.Write("You died from not eating enough, RIP:" + name);
            System.Threading.Thread.Sleep(3000);
            {
                System.Environment.Exit(1);
            }
        }
        if (hunger > 101)
        {
            Console.Write("You died from over feeding, RIP:" + name);
            System.Threading.Thread.Sleep(3000);
            {
                System.Environment.Exit(1);
            }
        }

    }

}

}
Kara
  • 6,115
  • 16
  • 50
  • 57
Ravaen
  • 49
  • 1
  • 7
  • 4
    Hello, the code shown has way too many issues, which makes it hard to answer your question. Please show a [MCVE](http://stackoverflow.com/help/mcve) demonstrating clearly your issue and the concept you're having trouble with, instead of pasting all your code. – Pierre-Luc Pineault Aug 11 '15 at 14:30
  • 1
    `while (hunger < 101) while (hunger > 1) while (thirst < 101) while (thirst > 1)` I don't believe this loop works the way you think it does; it's 4 nested loops and it will be looping indefinitely in the innermost (`thirst > 1`) without checking the outer conditions. First things first is to use a single `while` loop and combine the conditionals into it. That is: `while (hunger > 1 && hunger < 101 && thirst > 1 && thirst < 101)` Second is to use a curly brace block immediately after the `while` declaration; as it stands now I think it's only looping around your first `if` condition. – Chris Sinclair Aug 11 '15 at 14:32
  • You didn't validate your previous thread ... Then change all your while loop to `while (hunger < 101 && hunger > 1 && thirst < 101 && thirst > 1)` – Paradise228 Aug 11 '15 at 14:33
  • This question, as asked, is far too narrow to be useful to anyone else on SO. Can you generalize the question so that other people on SO would find it useful? – Sam Axe Aug 12 '15 at 22:01
  • Also, please do not post multiples of the same question. http://stackoverflow.com/questions/31946827/want-a-loop-that-checks-if-the-key-has-been-pressed – Sam Axe Aug 12 '15 at 22:14

0 Answers0