How to accept user input on one line?

I can improve C # programming. So, I'm just wondering how to enter user data on one line? this is my code and also i want to print the output on 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")); } } } 
+4
source share
3 answers

Try the following:

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

Just change Console.WriteLine to Console.Write .

+7
source

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

I think you mean it anyway, the question is not very clear.

0
source

I think you are asking if you can read both height and weight at the same time:

 // C equivalent printf ("Enter height (cm) and weight (kg): "); scanf ("%d %d\n", &h, &w); 

Yes, there are several alternatives.

Perhaps the easiest is to use Console.ReadLine () (how you do it) and parse the line.

You can also try several "Console.Read ()" (one for each argument).

0
source

Source: https://habr.com/ru/post/1435801/


All Articles