expected Unqualified-Id before switch

Jan 23, 2011 at 12:16pm
Hi i am a beginner at C++ ( i started yesterday) I am writing a program that translates date form format dd/mm to It is the <day> of <Month>

When i build the program i get error : expected Unqualified-Id before switch

also if someone could tell me how to loop the program so the user can do as many translations as he wants before closing the program

Here is the source code (W.I.P)
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
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
int nMonth;
cout << "Please Enter the day and Month";
cin >> nMonth;
}

switch (nMonth)

{
    case 1/1:
    cout << "Its the first of January" << end1;
    break;
    case 2/1:
    cout << "Its the second of January" << end1;
    break;
    default:
    caut   << " The date you entered is not valid"
            << " Restart and try again"
         << "Remember the format must be dd/mm"



system ("pause");
return 0;
}
Jan 23, 2011 at 12:27pm
1. Line 11, delete that }. That is saying "end the main function" which is not what you want to do.
2. Line 23, caut isn't a function :P
3. Line 26 needs a } to end the switch statement.
Jan 23, 2011 at 12:35pm
Thanks now my code looks like that
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
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
int nMonth;
cout << "Please Enter the day and Month";
cin >> nMonth;


switch (nMonth)

{
    case 1/1:
    cout << "Its the first of January" << end1;
    break;
    case 2/1:
    cout << "Its the second of January" << end1;
    break;
    default:
    cout    << "This is not valid input"
            << " Restart and try again"
         << "Remember the format must be dd/mm" <<end1;
}


system ("pause");
return 0;
}


But i get get fallowing error at line 17
1
2
error: 'end1' was not declared in this scope|
||=== Build finished: 1 errors, 0 warnings ===|
Last edited on Jan 23, 2011 at 12:36pm
Jan 23, 2011 at 3:04pm
It isn't "end1" it is "endl". It stands for end line. Didn't see it in the first post :P
Last edited on Jan 23, 2011 at 3:05pm
Jan 23, 2011 at 3:42pm
Thanks it helped
Topic archived. No new replies allowed.