我觉得这是一项非常简单的任务,但我只是在学习,如果有人能告诉我,这将是非常值得赞赏的。有人可以告诉我如何从一开始就重复这个小程序。谢谢!
我想重复所有这些:
#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;
}
答案 0 :(得分:3)
int main () {
while(true) {
//do everything
}
return 0;
}
标准的无限循环。
如果你想在用户结束循环时,例如,告诉你他们要输入0
(或更少)成绩,那么试试这个:
int main () {
while(true) {
// prompt and get input
if(grade_var <= 0) {
break;
}
// do stuff when they have grades
}
return 0;
}