gpt4 book ai didi

c++ - 如何退出 do while 循环? C++

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

<分区>

好的,在有人抨击我之前,我检查了每个论坛,试图帮助我解决这个问题,但不幸的是无法解决。有人可以指出正确的方向来解决这个问题吗?我试图在输入值 -1 时立即退出此 do while 循环。例如,当我输入 -1 时,我希望输出看起来像这样:

输入预计充电小时数://用户输入-1退出...

#include <iostream>
#include<iomanip>
using namespace std;

int main() {

float hour;
float Network1, Network2, Network3;

do {
cout << "Enter the expected number of hours charging:" << endl;
cin >> hour;

Network1= (1 * hour) + 10;
Network2= (2.50 * hour);
Network3 = (0.50 * hour) + 20;

cout << "Your expected costs are: " << endl;
cout << "Network 1: $" << fixed << setprecision(2) << Network1 << endl;
cout << "Network 2: $" << fixed << setprecision(2) << Network2 << endl;
cout << "Network 3: $" << fixed << setprecision(2) << Network3 << endl;

if(Network1 < Network2 && Network1 < Network3){
cout << "The lowest cost network is $" << Network1 << endl;
}
else if (Network2 < Network1 && Network2 < Network3){
cout << "The lowest cost network is $" << Network2 << endl;
}
else{
cout << "The lowest cost network is $" << Network3 << endl;
}
}
while (hour != -1) ;

cout << "Exiting..." << endl;

return 0;
}

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