0
我一直在编程为像,一周或什么东西,我不知道如何使一个程序重新启动C++一旦你已经达到结束。有人能帮我吗?C++如何在程序到达最后时重新启动程序?
我已经写过这个begginer字母评分程序,它根据你的分数告诉你,你得到了什么字母等级。但正如我所说,一旦你到达最后,你得到了答案,程序结束,如预期的,但我希望它重新启动,让我把另一个数字。谢谢!
#include <iostream>
using namespace std;
int main()
{
long int grade;
string x = " ";
cout << "Please, enter your grade. (0-100)" << endl;
cin >> grade;
int P =grade == 100;
int A =grade >= 90;
int B =grade >= 80;
int C =grade >= 70;
int D =grade >= 60;
int F =grade >= 0;
if(P){cout << "You have a perfect score." << endl << endl;}else{
if(A){cout <<"You have an A." << endl<< endl; }else{
if(B){cout <<"You have a B." << endl << endl;}else{
if(C){cout <<"You have a C." << endl;}else{
if(D){cout <<"You have a D." << endl<< endl;}else{
if(F){cout <<"You have an F."<< endl<< endl;}else{
cout << "Invalid input.";
}
}
}
}
}
}
cout << "Enter x to finish the program" << endl << endl;
cin >> x;
}
你需要的是一个循环。一个[关于C++的好书](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)可以教你关于循环。 –
欢迎来到Stack Overflow。请花些时间阅读[The Tour](http://stackoverflow.com/tour),并参阅[帮助中心](http://stackoverflow.com/help/asking)中的资料,了解您可以在这里问。 –
我想你应该阅读更多关于命令式语言的结构化编程基础知识。甚至维基百科都可以在这里帮助你:https://en.wikipedia.org/wiki/Structured_programming。 “重新启动程序”听起来很像“跳转到开始”,而这反过来听起来像'goto'声明,这是非结构化编程的祸根。您需要了解为什么**循环**是以结构化高级编程语言发明的,并使用它们。 –