// 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?)
#include <iostream>
usingnamespace 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;
}
#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.