### 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.
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.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156`` ``````#include 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.
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:

 ``123456789101112`` ``````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.