Good Afternoon,
This is my first class in C++ and I'm having problems with a program that needs to print a calendar of June, July and August 2008 into the output file "outCalendar.txt" . I should format the result for month well so that it looks like a real calendar table. So far I have this code.
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdlib>
#include <iomanip>
using namespace std;
int MonthDays[4]= {0,30,31,31,};
string MonthNames [4]={"Null","June","July","August"};
void printmonth( const int month, const int startday, const bool leapyear);
void showMenu();
int main( )
{
printmonth(6,6,false);
printmonth(7,0,false);
printmonth(8,1,false);
//file declaration
outCalendarFile; //output file to store the calendar
//variable declarations
int choice; //store choice value (1, 2, 0r 3)
char option; //store option value (y/n)
//open the output files
outCalendarFile.open("Lab_4_outputCalendar.txt");
while ( true )
{
showMenu(); //show menu
cin
>>choice; //get the user's choice
if (choice == 3 )
{void printmonth( const int month, const int startday, const bool leapyear)
{
int dayinmonth = MonthDays[month];
int daynumber=1;
int colCount=startday;
cout << " " << MonthNames[month] << endl;
cout << endl;
cout <<" Sun"<<" "<<"Mon"<<" "<<"Tue"<<" "<<"Wed" <<" "<<"Thu"<<" "<<"Fri"<<" "<<"Sat"<<endl;
cout << endl;
cout << setw((colCount*3)+startday) << "";
while (daynumber <= daysinmonth)
{
if (colCount ==8)
{
cout << endl;
colCount = 1;
}
cout << setw(4);
cout << daynumber;
colCount++;
daynumber++;
}
colCount = 1;
cout << endl << endl;
}
cout<<"Do you want to play again (y/n)? ";
cin>>option;
if (option !='y')
{
cout<<"Bye bye!"<<endl<<endl;
break;
}
}
//close files
outCalendarFile.close( ); //close outputCalendat.txt
return 0;
}
void showMenu()
{
cout<<"************************************************\n"
<<"Enter 1 to build a square root, log10 table \n"
<<"Enter 2 to play rolling two dices \n"
<<"Enter 3 to print a calendar for 2008 \n"
<<"What is your choice ==> ";
return;
}