Write a program to print a month when the number of days in the month and the first week day the month (0 to 6 for Sunday through Saturday) is given (See attached file for output).
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
int days,start_days;
int count=1;
do{
cout<<"Enter the number of days in the month(28,29,30,31): ";
cin>>days;
if(28>days || days>31){
cout<<"Wrong Input! \nEnter the number of days in the month(28,29,30,31): ";
cin>>days;
}
}
while (days<28 || days>31);
do{
cout<<"0-Sunday\n1-Monday\n2-Tuesday\n3-Wednesday\n4-Thrusday\n5-Friday\n6-Saturday"<<endl;
cout<<"Enter the start day(0 to 6): ";
cin>>start_days;
cout<<endl;
}
while(start_days<0 || start_days>=7);
cout<<setw(6);
cout<<" Sun Mon Tue Wed Thu Fri Sat"<<endl;
cout<<" --- --- --- --- --- --- ---"<<endl;
for(int space=1;space<=start_days;space++){
cout<<" ";
count+=1;
}
for(int i=1;i<=days;i++){
cout<<setw(4)<<i;
count+=1;
if (count>7){
cout<<endl;
count=1;
}
}
return 0;
}
0 Comments
Post a Comment