1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//function prototypes
int main()
{
ofstream outputFile;
outputFile.open("monthNames.txt", ios::app);
//declare array and variable
int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int month = 0;
char* array[12] = {"Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"};
cout << "Enter month number (1 for Jan - 12 for Dec | -1 to end): ";
cin >> month;
while (month != -1)
{
if (month < 1 || month > 12)
cout << "Invaild month number, choose from 1-12." << endl;
else
{
cout << "Month " << month << " has " << days[month -1] << " days." << endl;
}
cout << "Enter month number (1 for Jan - 12 for Dec | -1 to end): ";
cin >> month;
} //end while
outputFile.close();
system("pause");
return 0;
} //end of main function
|