I have to make a program that displays the value for given expressions in C++. So, I decided to make a switch/case and use it for calculating and displaying them! However, I have some problem with an error I get, which I can't solve...
#include <iostream>
using namespace std;
int main()
{
for(int i = 0; i < 6; i++){
int x = 5, y = 8;
switch case(i){
case 0:
x+=(++x)+(x++);
cout << "x+=(++x)+(x++) = " << x << endl;
break;
case 1:
x+=++y;
cout << "x+=++y = " << x << endl;
break;
case 2:
x+=2*x++;
cout << "x+=2*x++ = " << x << endl;
break;
case 3:
x=--y+x--+x;
cout << "x=--y+x--+x = " << x << endl;
break;
case 4:
x-=(-y)%3;
cout << "x-=(-y)%3 = " << x << endl;
break;
case 5:
y+=--y+x-y%x--;
cout << "y+=--y+x-y%x-- = " << y << endl;
break;
case 6:
x+=++y---x+y++;
cout << "x+=++y---x+y++ = " << x << endl;
break;
default:
cout << "Wrong value." << endl;
break;
}
}
return 0;
}
The line which returns an error is
switch case(i){
And also, there are two warnings, variables 'x' and 'y' not being used, but I do use them in each case. Should I separately declare them in each case? They must have the value 5 and 8 as beginning value for each case.