Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to take user input in the same line?

Tags:

c#

user-input

I'm bigener in C# programming So, I was just wondering about how to take user input in the same line? this is my code and also I want to print the output in the same line

using System;

namespace Wa2
{
  class BodyMassCalculation
  {
    public static void Main (string[] args)
    {
       Console.WriteLine ("BMI Calculator\n");

       double weight;
       Console.WriteLine ("Enter your weight in kilograms: ");
       weight = Convert.ToInt16(Console.ReadLine());

       double height;
       Console.WriteLine ("Enter your height in centimetres: ");
       height = Convert.ToInt16(Console.ReadLine());

       double meter;
       meter = height / 100;

       Double BMI;
       BMI = (weight) / (meter*meter);
       Console.WriteLine ("Your BMI is " , BMI);
       Console.WriteLine(BMI.ToString("00.00"));
    }
  }
}
like image 218
user1692696 Avatar asked Sep 23 '12 21:09

user1692696


Video Answer


2 Answers

Try this:

Console.Write("Enter your input here: ");
string userinput = Console.ReadLine();

Just change Console.WriteLine to Console.Write.

like image 145
matthewr Avatar answered Sep 22 '22 02:09

matthewr


Use Console.Write() instead of Console.WriteLine().

I think that's what you mean anyway, the question isn't very clear.

like image 23
Mister Bee Avatar answered Sep 22 '22 02:09

Mister Bee