3 errors (learning function stuff now)

hi everyone
my script calculates what day of the week it is on a specific day
(it's dutch, i'll translate it if i have to)
here he is:
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
#include <iostream.h>
#include <stdlib.h>
// kijkt hoeveel dagen er verstreken zijn; sinds maandag 01-01-1900
// dag = de dag (van de maand)
// maand = de maand (in nummers)
// jaar = het jaar (4 cijfers)
// returns: hoeveel dagen er verstreken zijn
int verstreken(int dag, int maand, int jaar)
{
    int myDagen_2;
    int myDagen_1 = dag;
    if (maand == 1)
    {
       myDagen_2 = 0;
    }
    else if (maand == 2)
    {
       myDagen_2 = 31;
    }
    else if (maand == 3)
    {
       myDagen_2 = 59;
    }
    else if (maand == 4)
    {
       myDagen_2 = 90;
    }
    else if (maand == 5)
    {
       myDagen_2 = 120;
    }
    else if (maand == 6)
    {
       myDagen_2 = 151;
    }
    else if (maand == 7)
    {
       myDagen_2 = 181;
    }
    else if (maand == 8)
    {
       myDagen_2 = 212;
    }
    else if (maand == 9)
    {
       myDagen_2 = 243;
    }
    else if (maand == 10)
    {
       myDagen_2 = 273;
    }
    else if (maand == 11)
    {
       myDagen_2 = 304;
    }
    else if (maand == 12)
    {
       myDagen_2 = 334;
    }
    int myJaarVoorbij = jaar - 1900;
    int myDagen_3 = myJaarVoorbij * 365;
    if (maand < 1 && dag < 28)
    {
       myDagen_3 = myDagen_3 + myJaarVoorbij / 4;
    }
    int myDagen = myDagen_1 + myDagen_2 + myDagen_3 - 1;
    return myDagen;
}
//kijkt welke dag van de week het is
//verstreken = het aantal dagen dat verstreken is sinds 1 jan. 1900 (maandag)
//returns = maandag, dinsdag, woensdag, donderdag, vrijdag, zaterdag, zondag
string Weekdag(int verstreken)
    {
     verstreken %= 7;
     int myWeekdag;
     if (verstreken == 0)
     {
        myWeekdag = "maandag";
     }
     if (verstreken == 1)
     {
        myWeekdag = "dinsdag";
     }
     if (verstreken == 2)
     {
        myWeekdag = "woensdag";
     }
     if (verstreken == 3)
     {
        myWeekdag = "donderdag";
     }
     if (verstreken == 4)
     {
        myWeekdag = "vrijdag";
     }
     if (verstreken == 5)
     {
        myWeekdag = "zaterdag";
     }
     if (verstreken == 6)
     {
        myWeekdag = "zondag";
     }
     return myWeekdag;
    }
//het programma zelf
int main()
{
      cout << "op 28 feb 1904 zijn er " << verstreken(28, 2, 1904) << " dagen verstreken sinds 1 januari 1900." << endl << "Het is dan een " << weekdag(verstreken(28, 2, 1904)) << "." << endl;
      system("PAUSE");
      return 0;
}

this are the errors:
syntax error before '(' // line 72
parse error before 'if' // line 76
implicit declaration of function 'int weekdag(...)' // line 109

i hope someone can help me...
Last edited on
I don't see that you declared "Weekdag" in the header area.

line 72: don't know.

line 76: What's a parse error? Don't know.

EDIT IN RESPONSE TO simpleasy Jul 4, 2008 at 6:56am: Yes, simpleasy, you used the function "Weekdag" from lines 72-105, but you failed to declare it anywhere. You MUST have a declaration for a function, unless it is your main() function.
Last edited on
what do you meen? there is a function named Weekdag
he starts on line 72 and ends on line 105
weekdag is btw weekday in english ;)
Hello,

the line 72 error may be that, and I am not really sure, a function fo type string may not be declared? Try "char weekdag"
The lien 76 error seems to be a logical follow up on the weekdag-function error.


regards and greetings to the Netherlands

int main
now that 3 errors are gone, but i have new one:

there are 7 errors, always at the return-line, and the last error stays the same, but if the other 7 are solved, that one will work to i gues..
so, here are the 7 important errors:
line 78: assignment to 'int' from 'const char*' lacks a cast
line 82: assignment to 'int' from 'const char*' lacks a cast
line 86: assignment to 'int' from 'const char*' lacks a cast
line 90: assignment to 'int' from 'const char*' lacks a cast
line 94: assignment to 'int' from 'const char*' lacks a cast
line 98: assignment to 'int' from 'const char*' lacks a cast
line 102: assignment to 'int' from 'const char*' lacks a cast

Last edited on
closed account (z05DSL3A)
Look for the //changed and //added comments

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
#include <iostream>  //Changed
//               ~~
#include <stdlib.h>
#include <string>    // Added
//~~~~~~~~~~~~~~~


// kijkt hoeveel dagen er verstreken zijn; sinds maandag 01-01-1900
// dag = de dag (van de maand)
// maand = de maand (in nummers)
// jaar = het jaar (4 cijfers)
// returns: hoeveel dagen er verstreken zijn
int verstreken(int dag, int maand, int jaar)
{
    int myDagen_2;
    int myDagen_1 = dag;
    if (maand == 1)
    {
       myDagen_2 = 0;
    }
    else if (maand == 2)
    {
       myDagen_2 = 31;
    }
    else if (maand == 3)
    {
       myDagen_2 = 59;
    }
    else if (maand == 4)
    {
       myDagen_2 = 90;
    }
    else if (maand == 5)
    {
       myDagen_2 = 120;
    }
    else if (maand == 6)
    {
       myDagen_2 = 151;
    }
    else if (maand == 7)
    {
       myDagen_2 = 181;
    }
    else if (maand == 8)
    {
       myDagen_2 = 212;
    }
    else if (maand == 9)
    {
       myDagen_2 = 243;
    }
    else if (maand == 10)
    {
       myDagen_2 = 273;
    }
    else if (maand == 11)
    {
       myDagen_2 = 304;
    }
    else if (maand == 12)
    {
       myDagen_2 = 334;
    }
    int myJaarVoorbij = jaar - 1900;
    int myDagen_3 = myJaarVoorbij * 365;
    if (maand < 1 && dag < 28)
    {
       myDagen_3 = myDagen_3 + myJaarVoorbij / 4;
    }
    int myDagen = myDagen_1 + myDagen_2 + myDagen_3 - 1;
    return myDagen;
}
//kijkt welke dag van de week het is
//verstreken = het aantal dagen dat verstreken is sinds 1 jan. 1900 (maandag)
//returns = maandag, dinsdag, woensdag, donderdag, vrijdag, zaterdag, zondag

std::string Weekdag(int verstreken) //changed
//~~~
{
     verstreken %= 7;
     std::string myWeekdag; //changed
     //~~~~~~~
     if (verstreken == 0)
     {
        myWeekdag = "maandag";
     }
     if (verstreken == 1)
     {
        myWeekdag = "dinsdag";
     }
     if (verstreken == 2)
     {
        myWeekdag = "woensdag";
     }
     if (verstreken == 3)
     {
        myWeekdag = "donderdag";
     }
     if (verstreken == 4)
     {
        myWeekdag = "vrijdag";
     }
     if (verstreken == 5)
     {
        myWeekdag = "zaterdag";
     }
     if (verstreken == 6)
     {
        myWeekdag = "zondag";
     }
     return myWeekdag;
    }
//het programma zelf
int main()
{
    std::cout << "op 28 feb 1904 zijn er " << verstreken(28, 2, 1904) << " dagen verstreken sinds 1 januari 1900." << std::endl; //changed
    //~~~                                                                                                             ~~~~~
    std::cout << "Het is dan een " << Weekdag(verstreken(28, 2, 1904)) << "." << std::endl; //changed
    //~~~                             ~                                          ~~~~~ 
      system("PAUSE");
      return 0;
}
Last edited on
great! it works
but could you please explain why there sometimes have to stand 'std::' before something?
and where can i find some explaination of al the includestuff? beacouse i don't get the point of it :P
closed account (z05DSL3A)
The standard C++ library has its elements defined in the Namespace[1] called std, to resolve the name of an element in your code you use the namespace name followed by the resolution operator :: eg std::cout, you could also put using namespace std; just after the #includes section this will allow you to use the elements of the namespace without using std:: in front of it.

[1] http://www.cplusplus.com/doc/tutorial/namespaces.html
Last edited on
Topic archived. No new replies allowed.