+ 1
How to get rid of errors of compilation.
#include <iostream> using namespace std; int main() { int k; int p; double i1; double i2; int s; int result; int r; cin >> r; cin >> k; cin >> p; cin >> s; switch (r);{ case 0:; {i1 = (k * p) / 100; i2 = k + i1; result = s / i2; cout << result; break;} case 1:; {i1 = (k * p) / 100; i2 = k - i1; result = s / i2; cout << result; break; } default; {cout << "Warning! You should type 0 or 1"; break; }} return 0; }
6 ответов
0
your case statements should be just case : not case :;
0
I have deleted all the semicolons, where it was needed. But I still get compilation error.
0
oh, the switch statement has a ; in front of it, that shouldn't be there. it should be
switch(r)
{
case 0:
{code}
case 1:
{code}
default:
{code}
}
0
what about break?
0
what do you mean? it's part of the code section
0
you should write your code something like thing so that the user knows what to type ;)
#include <iostream>
using namespace std;
int main()
{
int k, p, s, r, result;
double i1, i2;
cout<<"enter k "<<endl;
cin >> k;
cout<<"enter p "<<endl;
cin >> p;
cout<<"enter s "<<endl;
cin >> s;
cout<<"enter a choice 0 or 1 and press enter"<<endl;
cin >> r;
switch (r)
{ case 0:
i1 = (k * p) / 100;
i2 = k + i1;
result = s / i2;
cout << result;
break;
case 1:
i1 = (k * p) / 100;
i2 = k - i1;
result = s / i2;
cout << result;
break;
default:
cout << "Warning! You should type 0 or 1";
break;
}
return 0;
}