G
Guest
My function use cin to get a input data, if my input is smaller enough, it
works fine; but if input a very large number ,i.e. a number out of the data
defined range, the program will go to unstable state, repeatedly print out
"Please input an interger(0 ~ 4,294,967,295): ", what should I do to catch
the exception for it?
thanks.
include <fstream>
#include <iostream>
using namespace std;
void boothRepresent(unsigned int input, char * booth);
void printBooth(char * booth, int length);
int main(int arg, char** args) {
char booth[33];
unsigned int input;
while(1) {
cout << "\nPlease input an interger(0 ~ 4,294,967,295): ";
cin >> input;
cout << endl;
if(cin) {
boothRepresent(input, booth);
cout << "Booth representation:" << endl;
printBooth(booth, 33);
}
}
return 0;
}
works fine; but if input a very large number ,i.e. a number out of the data
defined range, the program will go to unstable state, repeatedly print out
"Please input an interger(0 ~ 4,294,967,295): ", what should I do to catch
the exception for it?
thanks.
include <fstream>
#include <iostream>
using namespace std;
void boothRepresent(unsigned int input, char * booth);
void printBooth(char * booth, int length);
int main(int arg, char** args) {
char booth[33];
unsigned int input;
while(1) {
cout << "\nPlease input an interger(0 ~ 4,294,967,295): ";
cin >> input;
cout << endl;
if(cin) {
boothRepresent(input, booth);
cout << "Booth representation:" << endl;
printBooth(booth, 33);
}
}
return 0;
}