Can anyone help me identify what is wrong with this? It was supposed to be a c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anyone help me identify what is wrong with this? It was supposed to be a c++

int main() { int a,b,c, ope; cout<<"enter a value" << endl cin > a; cout<<"enter b value" <<endl cin > b; cout<<"enter operation (+ - * / and %)"; cin> ope; if (ope == +) c=a+b; cout<< c; break; } if (ope == -) { c=a-b; cout<< c; break; } else if (ope == *) { c=a*b; cout<< c; break; } else if (ope == /) { c= a/b; cout<< c; break; } else if (ope == %) { c=a%b; cout<< c else cout<<"entered wrong input"; return 0;

31st May 2023, 10:40 AM
Ralph Joel Torcuator
Ralph Joel Torcuator - avatar
2 Answers
+ 9
Oh. There are lot more mistakes. # In c++, Every statement should end with semicolon. You are missing semi colon after endl ;👈 some other places also. Recheck. # if ope is of integer type, you can only store in it a integer. Inputting a character will not be accepted so then it stores default value 0. # ( ope == + ) , character must be enclosed in single quotes like '+'.otherwise it is invalid statement. # break statement can only be required and used in loops. No need in if block. It's an error. So remove break statements. # { is missing for first if block. # properly check if(){ ...} else if(..) {.. } .. else { } block structures.. # > greater than operator, >> input stream operator. Not interchangeable. # include needed headers. # close program properly.. Try these points in your code.. Hope it helps.....
31st May 2023, 11:05 AM
Jayakrishna 🇮🇳
+ 5
Operators supposed to be characters. How can you store it in integer types? Take ope's as charecter type and modify code accordingly.. For anything, anytime, save code and share link for quick and accurate responses.. Hope it helps..
31st May 2023, 10:47 AM
Jayakrishna 🇮🇳