Wheres the error? (Calendars Zeller Algortim)

Hi everyone

I have a problem whit the zeller algorithm, declarated as a defined funcion, and using this to calculate the weeks day and next using a for to calculate all days of the selected month based on also selected year by the user, and finally print the process like a month calendar,but i have error compiling the code i thinkt that all the esentences, fors... etc are correct, i show you the fount code:




#include <stdio.h>








int main() {










int anno, mes, dia, w, x, y, i, n, h;











int algoritmozeller (int anno, int mes, int i ) {




if(mes<=2) {

mes = mes + 12;
anno = anno - 1;

}


else {

mes = mes - 2;

}


y = anno % 100;

w = anno / 100;



h = (( 700 + (( 26 * mes - 2)/10) + i + y + (y/4) + (w/4) + 5 * w) % 7);

return (h);

}





printf("anno");

scanf(" %d", &anno);


printf(" mes ");

scanf(" %d", &mes);









if(anno < 1601 && anno > 3000) {





if (mes == 1) {

printf( " Enero");

}

if( mes == 2) {

printf( " Febrero");

}

if(mes == 3) {

printf("Marzo");

}


if(mes == 4) {


printf("Abril");


}


if ( mes == 5) {


printf("Mayo");

}

if ( mes == 6) {

printf("Junio");

}


if ( mes == 7) {

printf("Julio");


}

if ( mes == 8) {

printf("Agosto");

}


if (mes == 9) {


printf("Septiembre");


}

if (mes == 10) {

printf("Octubre");

}


if (mes == 11) {


printf("Noviembre");

}

if ( mes == 12) {

printf("Diciembre");

}

printf(" %d\n", anno);
printf(" \n");


printf("===========================\n");

printf("LU MA MI JU VI SA DO\n");

printf("===========================\n");


bisiesto = (anno % 4) == 0;

if( mes == 2 && bisiesto) {



n = 1;

}

if(mes == 3) {

n = 3;

}

if( mes == 4) {

n = 2;


}

if(mes == 5) {

n = 3;


}

if( mes == 6) {

n = 2;


}

if ( mes == 7 && mes == 8) {

n = 3;

}

if(mes == 9 && mes == 11) {

n = 2;

}

if(mes == 10 && mes == 12) {

n = 3;


}

if(i < 8) {

while(i < 8) {

h = algoritmozell( int anno, int mes, int dia )


printf("%d ", h);


i++;


}


}


if(i == 8 && i < 8) {


while(i + 7 < 28 + n) {







h = algoritmozell( int anno, int mes, int dia ) + 7;


if(i < 7)


printf("%d ", h);

}


if(i == 7) {

printf("%d\n", h);
i++;

}

if(i < 14) {

printf("%d", h);


}

if(i == 14) {

printf("%d\n", h);


}

if(i < 21) {

printf("%d ",h);


if(i == 21 && i == 28) {

printf("%d ",h);

}

if(i < 28) {

printf("%d ",h);


}

if(i < 31) {

printf("%d ",h);






































}


}

}
}

}




Last edited on
Firstly, put your code between [code ] and [/code]
You are declaring and defining algoritmozeller function in main... move the definition outside main function,and call this from main.
Read this,http://www.cplusplus.com/doc/tutorial/functions/ :)
closed account (49iURXSz)
There seems to be an extra bracket at the end of your code.

Here is what the code looks like formatted properly and without the extra bracket...

Note: For the single if statements, I removed the brackets and some spacing to reduce the size of this post. Remember that C++ will allow you to use conditionals and loops without brackets; but it only works properly for one statement.

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <stdio.h>

int main() {

	int anno, mes, dia, w, x, y, i, n, h;

	int algoritmozeller (int anno, int mes, int i ) {

		if(mes<=2) {
			mes = mes + 12;
			anno = anno - 1;
		}

		else 
		{
			mes = mes - 2;
		}

		y = anno % 100;
		w = anno / 100;

		h = (( 700 + (( 26 * mes - 2)/10) + i + y + (y/4) + (w/4) + 5 * w) % 7);

		return (h);

	}

	printf("anno");
	scanf(" %d", &anno);

	printf(" mes ");
	scanf(" %d", &mes);

	if(anno < 1601 && anno > 3000) {

		if (mes == 1)
			printf( " Enero");

		if (mes == 2)
			printf( " Febrero");

		if (mes == 3)
			printf("Marzo");

		if (mes == 4)
			printf("Abril");

		if (mes == 5)
			printf("Mayo");

		if (mes == 6)
			printf("Junio");

		if (mes == 7)
			printf("Julio");
			
		if (mes == 8)
			printf("Agosto");
			
		if (mes == 9)
			printf("Septiembre");
			
		if (mes == 10)
			printf("Octubre");

		if (mes == 11)
			printf("Noviembre");

		if (mes == 12)
			printf("Diciembre");

		printf(" %d\n", anno);
		printf(" \n");

		printf("===========================\n");

		printf("LU MA MI JU VI SA DO\n");

		printf("===========================\n");

		bisiesto = (anno % 4) == 0;

		if( mes == 2 && bisiesto)
			n = 1;

		if(mes == 3)
			n = 3;

		if( mes == 4)
			n = 2;

		if(mes == 5)
			n = 3;

		if( mes == 6)
			n = 2;

		if ( mes == 7 && mes == 8)
			n = 3;

		if(mes == 9 && mes == 11)
			n = 2;

		if(mes == 10 && mes == 12)
			n = 3;

		if(i < 8) {
			while(i < 8) 
			{
				h = algoritmozell( int anno, int mes, int dia )
				printf("%d ", h);

				i++;
			}
		}


		if(i == 8 && i < 8) {


		while(i + 7 < 28 + n) 
		{
			h = algoritmozell( int anno, int mes, int dia ) + 7;

			if(i < 7)

			printf("%d ", h);
		}


		if(i == 7)
		{
			printf("%d\n", h);
			i++;
		}

		if(i < 14)
			printf("%d", h);

		if(i == 14)
			printf("%d\n", h);

		if(i < 21)
			printf("%d ",h);

		if(i == 21 && i == 28)
			printf("%d ",h);
			
		if(i < 28)
			printf("%d ",h);

		if(i < 31)
			printf("%d ",h);
		}
	}
}
Oh thank you very much i tought that your code is perfect, then i dont understend why my compiler still saying that element not expected in the line seven:(Code bloks)

int algoritmozeller (int anno, int mes, int i ) {

Element not expected

Dev c++ compiler :


7 a function-definition is not allowed here before '{' token

7 expected `,' or `;' before '{' token








A function is not created in main, you usually create the function under main and then call it in main, I believe that's why. I might not be correct, I'm still a beginner as well.
closed account (49iURXSz)
zENZEz is correct; you cannot define a function in another function. You must first move the function code outside of main and then call it in main.

So:

1
2
3
4
5
6
7
8
9
10
11
12
void myLittleFunction();    // Function Prototype ( Declaration )

int main()
{
    myLittleFunction();    // Function Call
}

void myLittleFunction()   // Function Definition
{
    cout << "I am a tiny little function." << endl;
}


But this is a procedure, i write a function, i put out the declaration outside the main and work but when i invocated after give me error :




if(i < 8) {
while(i < 8)
{
h = algoritmozell( int anno, int mes, int dia )
printf("%d ", h);

i++;
}
}


if(i == 8 && i < 8) {


while(i + 7 < 28 + n)
{
h = algoritmozell( int anno, int mes, int dia ) + 7;

if(i < 7)

printf("%d ", h);
}
Topic archived. No new replies allowed.