不管用goto还是while都是无限循环,求问这是为什么
代码如下:
#include <iostream>
#include <stdexcept>
#include <exception>
using namespace::std;
int main(){
int a, result{ 1 };
cout << "input a number:" << endl;
// retry:
// try{
// cin >> a;
// if (cin.fail())
// throw runtime_error("not a number!");
// }catch(runtime_error e){
// cout << e.what() << endl;
// goto retry;
// }
while(!(cin >> a)){
cout << "not a number!" << endl;
}
do{
result *= a;
}while(a-- > 1);
cout << "result is:\n\t" << result << endl;
return 0;
}