程序不被识别为内部或外部命令,可操作程序或批处理文件

时间:2015-03-04 18:57:09

标签: c++

标题说我目前正在制作一个C ++程序。 Visual Studio报告没有错误,但是当我尝试运行它时它只是给了我那个错误。 我正在做的程序应该确定用户输入月份的一个月中的天数,以及它是否是闰年。代码如下,任何帮助表示赞赏:)

#include <iostream>
#include <ctime>
#include <string>
using namespace std;


enum MONTH { JAN, FEB, MARCH, APR, MAY, JUNE, JULY, AUG, SEP, OCT, NOV, DEC };
const string NAME_OF_MONTH[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
const int DAYS_IN_MONTH[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };


void getInput(int &month, int &year)
{
cout << "Enter a month number (1-12) and a 4 digit year " << endl;
cout << "separated by a space (or 0 0 to quit): ";
cin >> month >> year;

while (month < 0 || month > 12)
    {
        cout << "Month number must be between 1 and 12 (or 0 to quit)" << endl;
        cout << "Please re-enter month: ";
        cin >> month;
    }
}

void getCurrMonAndYear(int &month, int&year)
{
    time_t epochSeconds = time(NULL);

    tm * tm_ptr = localtime(&epochSeconds);

    month = tm_ptr->tm_mon;
    year = tm_ptr->tm_year + 1900;
}

bool isLeapYear(int year)
{
    if (year % 100 == 0)
        return (year % 400 == 0);
    else
        return (year % 4 == 0);
}

int numDaysInMonth(int month, int year)
{
    int numberOfDays = DAYS_IN_MONTH[month];

    if (month == FEB && isLeapYear(year))
        numberOfDays++;

    return numberOfDays;
}


int main() {

    int month;
    int year;

    getInput(month, year);

    while (month != 0)
    {
        month--;

        cout << numDaysInMonth(month, year) << "days." << endl;

        getInput(month, year);
    }
    cout << endl;

    getCurrMonAndYear(month, year);
    cout << "The current month, " << NAME_OF_MONTH[month] << " " << year << ",";
    cout << " has " << numDaysInMonth(month, year) << " days." << endl;

    return 0;
}

0 个答案:

没有答案