39 lines
797 B
C++
39 lines
797 B
C++
#include <iostream>
|
|
using namespace std;
|
|
|
|
int parseInt(){
|
|
int num;
|
|
cout << "Enter a whole number: ";
|
|
cin >> num;
|
|
while(cin.fail() || cin.peek() == '.'){
|
|
cout << "Whoops. Enter a whole number: ";
|
|
cin.clear();
|
|
cin.ignore(256,'\n');
|
|
//cout << "Next char is: " << cin.peek() << endl;
|
|
cin >> num;
|
|
}
|
|
return num;
|
|
}
|
|
|
|
double parseDouble(){
|
|
double num;
|
|
cout << "Enter a number: ";
|
|
cin >> num;
|
|
while(cin.fail()){
|
|
cout << "Whoops. Enter a number: ";
|
|
cin.clear();
|
|
cin.ignore(256,'\n');
|
|
//cout << "Next char is: " << cin.peek() << endl;
|
|
cin >> num;
|
|
}
|
|
return num;
|
|
}
|
|
|
|
int main(){
|
|
int num = parseInt();
|
|
cout << "You entered: " << num << endl;
|
|
double dubstep = parseDouble();
|
|
cout << "Here's your double: " << dubstep << endl;
|
|
|
|
return 0;
|
|
} |