gpt4 book ai didi

C++ While 循环不会重复

转载 作者:太空宇宙 更新时间:2023-11-03 10:24:55 26 4
gpt4 key购买 nike

我试图让程序中的 WHILE 循环重复。我已经在这里待了大约 4 个小时,所以也许我只是错过了一些东西。

无论我输入什么,我都无法让循环重复。此外,如果我在提示中输入多个字符,那么它会跳过所有 7 个后续循环。

然后,更好的是,当输入内容时,最后的变量甚至不会改变,希望你能帮助我解决上面列出的所有问题(越简单越好)。但此时我只需要一个。

    cout << "Welcome. Input anything to start the sales reporting process.\n\n";
cin >> start; **//If I enter more than one character here it skips my other loops**
if (start == start)
{
cout << "\n\nPlease enter the amount of each sale for Darwin when prompted, only enter one at a time.\n";
cout << "When you are finished entering sales, input a '1'.\n\n";
cout << "Enter a sale for Darwin: ";
cin >> darwinSale;
cout << endl << endl;
while(darwinSale =! 1)
{
cout << "Enter a sale for Darwin: ";
cin >> darwinSale;
if (darwinSale <= 50999)
darwinCom = darwinSale * 0.04;
if (darwinSale >= 51000 and darwinSale <= 125999)
darwinCom = darwinSale * 0.05;
if (darwinSale >= 126000 and darwinSale <= 200999)
darwinCom = darwinSale * 0.06;
if (darwinSale >= 201000)
darwinCom = darwinSale * 0.07;
darwinComTotal = darwinComTotal + darwinCom;
darwinTotal = darwinSale + darwinTotal;
cout << endl << endl;
}

最佳答案

在你的 while 条件下,你实际上是在检查:

while(drawinSale = !1)

并且 !1 检查 1 == NULL 是否返回 0

您应该改为执行以下操作:

while(drawinSale != 1)

关于C++ While 循环不会重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39986183/

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