How to get rid of errors of compilation. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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; }

25th Oct 2016, 4:39 PM
Misha Vinokurov
Misha Vinokurov - avatar
6 Answers
0
your case statements should be just case : not case :;
25th Oct 2016, 4:51 PM
Daniel Rollins
Daniel Rollins - avatar
0
I have deleted all the semicolons, where it was needed. But I still get compilation error.
25th Oct 2016, 5:01 PM
Misha Vinokurov
Misha Vinokurov - avatar
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} }
25th Oct 2016, 5:10 PM
Daniel Rollins
Daniel Rollins - avatar
0
what about break?
25th Oct 2016, 5:30 PM
Misha Vinokurov
Misha Vinokurov - avatar
0
what do you mean? it's part of the code section
25th Oct 2016, 5:35 PM
Daniel Rollins
Daniel Rollins - avatar
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; }
25th Oct 2016, 6:03 PM
Digbose Hazarika
Digbose Hazarika - avatar