calender program help *

hello i need help with my programming class(high school) i have most of the code but i cant manage to put the pieces in the right places. the program is to make calender that asks the user to type in the month, asks the how many days there are in that month and finally ask the start date. here is my code so far ( i use Microsoft visual studio):
#include<iostream>
#include<string>
using namespace std;
int main()
{
string month;
int days=0;
int sday=0;
cout<<"Enter the name of the month: "<<endl;
cin>>month;
cout<<"Enter the total number of days: "<<endl;
cin>>days;
cout<<"Enter the starting day (0 for Sunday) :"<<endl;
cin>>sday;
system("cls");


cout<< month <<endl;
cout.setf(ios::left);
cout.width(10);
cout<<"S M T W R F S"<<endl;
cout.width(10);
cout<<"------------------------------------------------"<<endl;
for(int day=1;day<=days;day++)
{
cout.width(8);
cout<<day;
if (day%7==0)
cout<<endl;
for(sday=0;sday<=6;sday++)

if((day+sday)%7==0)
cout<<"";
cout<<days;

return 0;


}


return 0;
}
What is your question?

From what I see, you're not starting the month on the right day.
What's the point of the cout of the null string at line 29?
Why are you outputting the number of days at line 30?

PLEASE USE CODE TAGS (the <> formatting button) when posing code. It makes it easier to help you.

heres my new code. if you run it you will see what i am talking about. you will get a calender but it doesn't account for the starting day of the user input. so my question is how can i account for the user wanting to start the day on another day
#include<iostream>
#include<string>
using namespace std;
int main()
{
string month;
int days=0;
int sday=0;
int day=0;
cout<<"Enter the name of the month: "<<endl;
cin>>month;
cout<<"Enter the total number of days: "<<endl;
cin>>days;
cout<<"Enter the starting day (0 for Sunday) :"<<endl;
cin>>sday;
system("cls");


cout<< month <<endl;
cout.setf(ios::left);
cout.width(10);
cout<<"S M T W R F S"<<endl;
cout.width(10);
cout<<"------------------------------------------------"<<endl;
for(day=1;day<=days;day++)
{
cout.width(8);
cout<<day;
if (day%7==0)
cout<<endl;

}



return 0;

}
y
Last edited on
Write a program that prompts the user to enter the name of the month, the total number of days in the month and the day of the week the month begins on. You may assume there will be no malicious input of any form. The first day of the month will be inputted as an integer ranging from 0 (Sunday) through 6 (Saturday). Please use some sort of width setting commands (and not just spaces or tabs you key in + constants where possible) to organize the columns. In order to clear a screen, the command is system(“cls”);
Use a for loop as the main driving loop to print the day numbers across the calendar.

You must match the sample output (note the program will run once – there are two samples shown here):


Enter the name of the month: October
Enter the total number of days: 31
Enter the starting day (0 for Sunday) : 1

< screen clears>



October

S M T W R F S
--------------------------------------
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


The next is a separate run entirely

Enter the name of the month: October
Enter the total number of days: 31
Enter the starting day (0 for Sunday) : 4

< screen clears>



October

S M T W R F S
--------------------------------------
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
You were asked to use code tags when posting code.

You need to space over sdays before you start your print loop.

You also need to keep track of which column you're in and output your endl when the column gets to 7 rather than when day gets to a multiple of 7.
Topic archived. No new replies allowed.