Ravaen
Ravaen

Reputation: 49

Want text to start on a new line

I'm making a console game were you take care of yourself so you don't overfeed or under feed. I'm having a issue that the text is not starting on a new line. how do I fix this?

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)");
        int hunger = 60;
        int thirst = 60;
        while (hunger < 101)
        while (hunger > 1) 
        while (thirst < 101)
        while (thirst > 1)

        {
            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 (hunger < 101)
        {
            Console.Write("You died from over feeding, RIP:" + name);
            System.Threading.Thread.Sleep(3000);
            {
                System.Environment.Exit(1);
            }
        }

    }

}

}

I want the text to start on a new line when it tells the user its current food and water. How do I do this?

Upvotes: 0

Views: 142

Answers (3)

Paradise228
Paradise228

Reputation: 717

You should use Console.WriteLine instead of Console.Write

If you have a "complexe" string that you want to split you insert a '\n' where you want your backspace

EDIT : '\n' is specific to Windows plateform. As mentionned in comments, you can use Environment.NewLine if you are multi-platform driven.

Upvotes: 3

Jitendra soni
Jitendra soni

Reputation: 209

You can try below two options :-

1) String.Replace("Any Key word", Environment.NewLine);

2) Use "\n" in the string.

Thanks

Jitendra

Upvotes: 0

thatguy
thatguy

Reputation: 99

"\r\n" - windows

use to create a new line.

string newline = System.Environment.NewLine;

Upvotes: 0

Related Questions