gpt4 book ai didi

c++ - 我如何在循环中再次设置变量

转载 作者:行者123 更新时间:2023-11-28 06:03:58 24 4
gpt4 key购买 nike

我是 c++ 新手,对变量有疑问

int main() {
int a;
int b;
int c;
int e;
int parafechar;
int loop = 10;
while(loop==10) {
cout<< "Coloque a mensal 1\n";
cin >> a;
cout<< "Coloque a mensal 2\n";
cin >> e;
cout <<"Coloque a nota do cnem\n";
cin >> b;
cout << "Coloque a media dos trabalhos\n";
cin >> c;
if(a>b) {
cout << "A media e : " << a*0.5 + b*0.25 + c*0.25<<endl;
} else {
cout << "A media e : " << e*0.5 + b*0.25 + c*0.25<<endl;
}
cout << "aperte uma tecla para fechar o programa\n";
cin >> parafechar;
}
return 0;
}

在最后一行之后,我希望代码再次运行并再次设置所有变量,但程序无休止地运行,我该怎么办?(该程序是葡萄牙语,但它会计算成绩)感谢您的宝贵时间和帮助:)

最佳答案

after the last line i want the code to run again and all the variables to be set again but the program goes on endless, what should i do?

改变while中的检查,改变loop的值,使其最终满足条件停止循环。

while(loop > 0) {

// Do your stuff...

// Decrement loop. It will eventually become zero
// and the conditional in the while statement will fail.
--loop;
}

关于c++ - 我如何在循环中再次设置变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32752469/

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