Missing Function Header?

// switch.cpp : Defines the entry point for the console application.
//

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



{
char ch;
cout<<"Enter A Character ";
cin>>ch;
switch (ch)

case 'a':case'A':
cout<<ch<<" is a vowel";
break;
case'e':case'E':
cout<<ch<<" is a vowel";
break;
case'i':case'I':
cout<<ch<<" is a vowel";
break;
case'o':case'O':
cout<<ch<<" is a vowel";
break;
case'u':case'U':
cout<<ch<<" is a vowel";
break;
default:
cout<<ch<<" is a Consonant character";

}



When I run this program thid error is displayed:

error C2447: '{' : missing function header (old-style formal list?)

What do I do....Please Hep!
You probably want to put int main() after the third line.
The first problem is that the main() function is missing. This is the point at which execution of the program begins.

Secondly, the switch statement requires braces around the body of its code.

Something like this:
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
#include <iostream>

using namespace std;

int main()
{
    char ch;
    cout<<"Enter A Character ";
    cin>>ch;

    switch (ch)
    {
        case 'a':
        case 'A':
            cout<<ch<<" is a vowel";
            break;
        case 'e':
        case 'E':
            cout<<ch<<" is a vowel";
            break;
        case 'i':
        case 'I':
            cout<<ch<<" is a vowel";
            break;
        case 'o':
        case 'O':
            cout<<ch<<" is a vowel";
            break;
        case 'u':
        case 'U':
            cout<<ch<<" is a vowel";
            break;
        default:
            cout<<ch<<" is a Consonant character";
    }

    return 0;
}
Last edited on
Just to shorten it a bit:

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>

using  std::cout;
using std::cin;

int main()
{
    char ch;
    cout<<"Enter A Character \n";
    cin>>ch;

    switch (ch)
    {
        case 'a':
        case 'A':
        case 'e':
        case 'E':
        case 'i':
        case 'I':
        case 'o':
        case 'O':
        case 'u':
        case 'U':
            cout<<ch<<" is a vowel\n";
            break;
        default:
            cout<<ch<<" is a Consonant character\n";
    }

    return 0;
}

This makes use of execution falling through the cases.

Alternatively, you could use the toupper or tolower functions and shorten the switch even further.

HTH
Topic archived. No new replies allowed.