因此,我正在为任务编写第一个实际项目,尽管它正在执行预期的工作,但我需要使它看起来更具吸引力。更具体地说,当提示用户输入长度和宽度时,用户输入会出现在新行中(写在“输入草坪的长度/宽度:”下面。)如何使用户输入出现在问题旁边?感谢您的帮助!
using System;
using static System.Console;
namespace A2P1Lawn
{
public class Lawn
{
static void Main(string[] args)
{
int a = 25, b = 35, c = 50;
double area, numWeeks, option1, option2, option3;
WriteLine("Enter the Lawn's Length:");
double length = double.Parse(ReadLine());
WriteLine("Enter the Lawn's Width:");
double width = double.Parse(ReadLine());
string amtDue;
numWeeks = 20;
area = length * width;
WriteLine();
if (area < 400)
{
option1 = a * numWeeks;
amtDue = option1.ToString("C2");
WriteLine("For a {0} by {1} Lawn and an Area of {2} Square Feet, the Weekly Fee Would Come to: $25", length, width, area);
WriteLine("For the 20-Week Season, the Total Amount Due Would Come to " + amtDue);
WriteLine();
}
else if (area > 400 && area < 600)
{
option2 = b * numWeeks;
amtDue = option2.ToString("C2");
WriteLine("For a {0} by {1} Lawn and an Area of {2} Square Feet, the Weekly Fee Would Come to: $35", length, width, area);
WriteLine("For the 20-Week Season, the Total Amount Due Would Come to " + amtDue);
WriteLine();
}
else
{
option3 = c * numWeeks;
amtDue = option3.ToString("C2");
WriteLine("For a {0} by {1} Lawn and an Area of {2} Square Feet, the Weekly Fee Would Come to: $35", length, width, area);
WriteLine("For the 20-Week Season, the Total Amount Due Would Come to " + amtDue);
WriteLine();
}
}
}
}
答案 0 :(得分:0)
查看相关代码:
WriteLine("Enter the Lawn's Length:");
double length = double.Parse(ReadLine());
您正在使用Console.WriteLine()
输出提示文本。此命令将输出文本和一个换行符,该光标将光标移至下一行。
要将光标保持在同一行,只需使用Console.Write()
,例如:
Write("Enter the Lawn's Length:");
double length = double.Parse(ReadLine());
这将使您的输入光标与输出文本保持在同一行。