试图制作一个可靠和安全地向用户询问日期的三个组成部分的功能 - 日,月和年......我可以让它询问日期......但是我需要能够使它只能输入数字,不能输入字母,也不能混合字母和数字......
#include <iostream>
using namespace std;
int Day;
int Month;
int Year;
int GetYear(){
cout << "Enter a Year > ";
int nYear;
cin >> nYear;
cout << "Year: ";
Year = nYear;
return nYear;
}
int GetMonth(){
cout << "\nEnter a Month > ";
int nMonth;
cin >> nMonth;
cout << "Month: ";
Month = nMonth;
return nMonth;
}
int GetDay(int nMonth, int nYear){
cout << "\nEnter a Day > ";
int nDay;
cin >> nDay;
cout << "Day: ";
Day = nDay;
return nDay;
}
bool GetDate(int nDay, int nMonth, int nYear){
cout << "\nDate: ";
cout << nDay << "/" << nMonth << "/" << nYear << "\n";
return 0; //GetDate(Day, Month, Year);
}
void main() {
cout << GetYear();
cout << GetMonth();
cout << GetDay(Month, Year);
cout << GetDate(Day, Month, Year);
cout <<"Press Enter Key To Exist...";
cin.ignore (numeric_limits<streamsize>::max(), '\n' );
cin.get();
}