[英]I can't figure out how to repeat this whole program
I feel like this is a very simple task but I am just learning so if somebody can show me this is would be greatly appreciates. 我觉得这是一个非常简单的任务,但是我只是在学习,所以如果有人可以告诉我,这将是极大的感谢。 Can someone show me how to repeat this little program from the beginning. 有人可以告诉我如何从头开始重复这个小程序。 thanks! 谢谢!
I want to repeat all of this: 我想重复所有这些:
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main()
{
std::cout<<"Welcome to my grade book!\n";
int grade_var=0,grade_1=0,sum=0;
cout<<"Enter the number of grades you have:\t";
cin>>grade_var;
for(int i=1;i<=grade_var;i++)
{
cout<<endl<<"Enter the "<<i<<" number:\t";
cin>>grade_1;
sum=sum+grade_1;
}
sum=sum/grade_var;
cout<<endl<< sum;
cout<<endl<<"Letter Grade:\n";
if(sum>=96)
cout<<"A";
else
{
if(sum>=91)
cout<<"A-";
else
{
if(sum>=87)
cout<<"B+";
{
if(sum>=83)
cout<<"B";
else
{
if(sum>=80)
cout<<"B-";
else
{
if(sum>=77)
cout<<"C+";
else
{
if(sum>=73)
cout<<"C";
else
{
if(sum>=70)
cout<<"C-";
else
{
if(sum>=67)
cout<<"D+";
else
{
if(sum>=63)
cout<<"D";
else
{
if(sum>=60)
cout<<"D-";
else
cout<<"F";
}
}
}
}
}
}
}
}
}
}
return 0;
}
int main () {
while(true) {
//do everything
}
return 0;
}
Standard infinite loop stuff. 标准无限循环素材。
If you want to end the loop when the user, for example, tells you they have 0
(or fewer) grades to enter, then try this: 例如,如果要在用户告诉您输入0
(或更少)的成绩时结束循环,请尝试以下操作:
int main () {
while(true) {
// prompt and get input
if(grade_var <= 0) {
break;
}
// do stuff when they have grades
}
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.