C ++如何在程序结束后重新启动程序?

时间:2017-02-12 07:29:22

标签: c++ restart

我已经编程好了一周或者其他什么,而且一旦你到达终点,我就无法弄清楚如何在C ++中重新启动程序。有人能帮我吗?

我已经写了这个以字母为单位的程序,根据你的分数,你得到的字母等级来告诉你。但正如我所说,一旦你到达终点并且你得到了答案,程序会像预期的那样结束,但我希望它重新启动并让我输入另一个号码。谢谢!

#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;

}

1 个答案:

答案 0 :(得分:1)

将整个代码放在do while循环中,直到用户输入0来停止程序。

像这样:

    <?php
          $to = "root@localhost.com";
          $subject = "Hi!";
          $body="test";

          $headers = "From: root@localhost.com"; 

          if (mail($to, $subject, $body, $headers)) {
             echo "Message successfully sent!";
          } else {
             echo "Message delivery failed...";
          }
?>