gpt4 book ai didi

c# - 如何在同一行中获取用户输入?

转载 作者:太空狗 更新时间:2023-10-29 21:18:28 25 4
gpt4 key购买 nike

我更擅长 C# 编程所以,我只是想知道如何在同一行中接受用户输入?这是我的代码,我也想在同一行打印输出

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"));
}
}
}

最佳答案

试试这个:

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

只需将 Console.WriteLine 更改为 Console.Write

关于c# - 如何在同一行中获取用户输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12556279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com