我应该添加什么,以便 cin 在错误后重新启动?

问题描述 投票:0回答:0

这是代码,我希望终端从cin>>ipt重启;输入错误后再次输入。 *请忽略c1和c2

#include <iostream>
using namespace std;

int main ()
{

cout << "Hi, before starting the quiz you must input a number to verify" << endl; 
    cout << " " << endl; 

system ("pause");

string c1 = "Correct";
string c2 = "Incorrect"; 

srand(time(NULL));
int random = 1000+ (rand() % 9999);  
int ipt; 

    cout << "Please Input This Number :  " << random << endl; 
    cin >> ipt;
        if (ipt == random) {
            cout << "Number is correct" ; 
        }
        else 
        {
            cout << "Incorrect Number" << endl;
             
        }

return 0;
}

我希望在问题解决后,终端会在 cin>>ipt 重新启动;并且它会计算出<< "Incorrect number, please try again"; (does'nt replace cout << "Incorrect Number" << endl;)

c++ terminal restart
© www.soinside.com 2019 - 2024. All rights reserved.