I am in my first C++ class and I believe I have the switch statement about right but I keep getting an error.
The error is [Error] expected unqualified-id before 'switch'
Thanks in advance
switch (x) {
case 1:
case 2:
case 3:
cout << "x is 1, 2 or 3";
break;
default:
cout << "x is not 1, 2 nor 3";
break;
}
int myArray [] = {11, 9, 63, 27, 85};// my Array
int n, result=0;
int addition (int a, int b)
{
int r;
r=a+b;
return r;
}
int main()
switch (x) {
case 1:
case 2:
case 3:
cout << "x is 1, 2 or 3";
break;
default:
cout << "x is not 1, 2 nor 3";
break;
{
for ( n=0 ; n<5 ; ++n )
{
result += myArray[n];
}
int z;
z = addition (5,3);
cout << "The result is " << z;
double den, num, result;
char op;
do{
cout << "\nCalculator - Please enter a number :";
cin >> num;
cout << "Please enter a what kind of math +, -, *, /";
cin >> op;
cout << "Please enter second number :";
cin >> den;
if (op=='+') result=num+den;
// How the calculator calculates
if (op=='-') result=num-den;
if (op=='*') result=num*den;
if (op=='/') result=num/den;
cout<< result;
}
while (op!='e');
cout<<"HELLO WORLD MY NAME IS ERIC! "<< endl;
int myArray [] = {11, 9, 63, 27, 85};// my Array
int n, result=0;
int addition (int a, int b)
{
int r;
r=a+b;
return r;
}
int main(){
int t;
switch (t) {
case 1:
case 2:
case 3:
cout << "t is 1, 2 or 3";
break;
default:
cout << "t is not 1, 2 nor 3";
break;
}
{
for ( n=0 ; n<5 ; ++n )
{
result += myArray[n];
}
int z;
z = addition (5,3);
cout << "The result is " << z;
double den, num, result;
char op;
do{
cout << "\nCalculator - Please enter a number :";
cin >> num;
cout << "Please enter a what kind of math +, -, *, /";
cin >> op;
cout << "Please enter second number :";
cin >> den;
if (op=='+') result=num+den;
// How the calculator calculates
if (op=='-') result=num-den;
if (op=='*') result=num*den;
if (op=='/') result=num/den;
cout<< result;
}
while (op!='e');
cout<<"HELLO WORLD MY NAME IS ERIC! "<< endl;