cant get output right

i have been doing a calendar program.

this part works fine but the next part i am stuck on, this is what the
question asks,

it wants me to adapt the program so there are two inputs, the starting day and the number of days in the month, (0 is sunday, 1 is monday, etc.)
these two inputs are to be passed to the output function from main.

so basically it wants me to get the starting day in the month under the correct weekday.

if anyone has any ideas on how to do this i would really appreciate it. i have been trying to get it to work for hours.

here is what i have done.



#include "stdafx.h"
#include <iostream>
using namespace std;
#include <iomanip>



void output_month()
{
int i;
i=1;
int j;
cin>>j;




for (int i = 1; i <= j; i++)
{
cout<<setw(5)<<i;
if (i % 7 == 0)
{

cout << endl;
}

}

}




void main()
{
cout<<"Input an Integer";
cout<<endl;
output_month();//call


system("pause");
}

if i understood correctly what the program is supposed to do, i think that is what you want.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Input start: 3
Input number of days: 31
    S    M    T    W    T    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

Input start: 0 
Input number of days: 28
    S    M    T    W    T    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


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
37
38
39
40
41
42
#include <iostream>
using namespace std;
#include <iomanip>

void output_month(int start, int total) { 
	
	cout << "    S    M    T    W    T    F    S" << endl;
	cout << setw(5 * start ) << "";

	int i;
	for (i = 1; i <= total; i++) {
		
		cout << setw(5) << i; 
		if ((i + start) % 7 == 0) { 
			cout << endl;
		}
	}
	
	cout << endl;
	
	return;
}

int main() { 
	
	int i = 0;
	int j = 0;
	
	do {
		cout << "Input start: ";
		cin >> i;
	} while ((i < 0) || (i > 6));
	
	do {
		cout << "Input number of days: ";
		cin >> j;
	} while ((j > 31) || (j < 28));
	
	output_month(i, j);//call

	return 0;
}


(the previous code i posted had an error when entering 6 as start. fixed it now)
Last edited on
Topic archived. No new replies allowed.