我不明白为什么这段代码没有正常运行

时间:2017-02-10 02:01:25

标签: c++

/* Program Name: BadDate.cpp 
Function: This program determines if a date entered by the user is valid.  
Input:  Interactive
Output: Valid date is printed or user is alerted that an invalid date was entered
*/  

#include <iostream>
bool validateDate(int, int, int);
using namespace std;
 int main()
{ 
  // Declare variables

  int year;
  int month;
  int day;
  const int MIN_YEAR = 0, MIN_MONTH = 1, MAX_MONTH = 12, MIN_DAY = 1, MAX_DAY = 31; 
  bool validDate = true;

这是housekeeping()方法的工作    获取年份,然后是月份,然后是当天

int housekeeping() {
  cout << "Please enter a year: "<< endl;
  cin >> year;
  cout << "Please enter a month: "<< endl;
  cin >> month;
  cout << "Please enter a day: "<< endl;
  cin >> day;
}

这是detailLoop()方法的工作    检查以确保日期有效

int detailLoop() {
  if(year <= MIN_YEAR)  // invalid year
    validDate = false;
  else if (month < MIN_MONTH || month > MAX_MONTH)  // invalid month
    validDate = false;
  else if (day < MIN_DAY || day > MAX_DAY) // invalid day
    validDate = false; 
}

这是endOfJob()方法的工作    测试日期是否有效和输出日期以及它是否有效

int endOfJob() 
{
  if(validDate == true)
  { 
     // Output statement
     cout << " Your date is valid!"<< endl;
  }
  else
  {
     // Output statement
     cout << " Your date is not valid!"<< endl;
  }
}   
} // end of main() function

0 个答案:

没有答案