C# 执行While循环练习/w用户输入

C# 执行While循环练习/w用户输入,c#,while-loop,user-input,do-while,C#,While Loop,User Input,Do While,我正在为课堂写一个程序,需要一些关于如何让它工作的建议。我有一个程序,要求用户输入一个项目的价格。一旦他们输入了第一个项目的价格,它就会询问他们下一个价格。问题是我需要在do-while循环中使用它。我试图获得在while循环的每个实例之后输入的项目的总价。我知道我可以使用数组或列表,但分配不需要这样做。 任何建议都会有帮助 下面是do-while循环的代码 public static void Main() { double cost; int It

我正在为课堂写一个程序,需要一些关于如何让它工作的建议。我有一个程序,要求用户输入一个项目的价格。一旦他们输入了第一个项目的价格,它就会询问他们下一个价格。问题是我需要在do-while循环中使用它。我试图获得在while循环的每个实例之后输入的项目的总价。我知道我可以使用数组或列表,但分配不需要这样做。 任何建议都会有帮助

下面是do-while循环的代码

public static void Main()
    {


        double cost;
        int Items;
        string counter;
        string value;
        string more;
        double newtotal;
        int loopcounter = 0;

        //item cost
        Console.WriteLine("Welcome to the Online Store");
        Console.WriteLine("How many items are you buying?");
        counter = Console.ReadLine();
        Items = Convert.ToInt32(counter);

        do
        {
            // buying items

            Console.WriteLine("Enter the cost of your item one by one");
            value = Console.ReadLine();
            cost = Convert.ToDouble(value);
            newtotal = +cost; 
            loopcounter++;
        }

        while (loopcounter < Items);
publicstaticvoidmain()
{
双重成本;
国际项目;
字符串计数器;
字符串值;
多串;
双纽托;
int循环计数器=0;
//项目成本
Console.WriteLine(“欢迎来到在线商店”);
Console.WriteLine(“您要买多少件商品?”);
计数器=Console.ReadLine();
项目=转换为32(计数器);
做
{
//购买物品
Console.WriteLine(“逐个输入项目成本”);
value=Console.ReadLine();
成本=换算成双倍(价值);
新总额=+成本;
loopcounter++;
}
while(loopcounter
在newtotal=+cost之后写下面的代码;在do while中写下的语句:Console.WriteLine(“您的总金额:{0}”,newtotal);

在newtotal=+cost之后写下面的代码;在do while中写下的语句:Console.WriteLine(“您的总金额:{0}”,newtotal);

newtotal=+cost;是错误的 改为键入newtotal+=成本

移动

从循环中退出,因为你不必告诉买家一次又一次地进入

好的,继续保持下去。新的总成本是错误的 改为键入newtotal+=成本

移动

从循环中退出,因为你不必告诉买家一次又一次地进入


很好,继续保持它

侧注,它应该是
newtotal+=cost
现在的方式设置总成本,而不是添加到变量侧注,它应该是
newtotal+=cost
现在的方式设置总成本,而不是添加到变量
        Console.WriteLine("Enter the cost of your item one by one");