What is wrong with this case? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is wrong with this case?

case '%': cout << x % y; break;

3rd Nov 2018, 11:38 AM
Igor The Golden Fish
Igor The Golden Fish - avatar
4 Answers
+ 3
% only works or integers, but x and y are float in your code You should cast them in this case.
3rd Nov 2018, 11:51 AM
Matthias
Matthias - avatar
+ 1
Thanks)
3rd Nov 2018, 11:55 AM
Igor The Golden Fish
Igor The Golden Fish - avatar
0
write the link of the entire code
3rd Nov 2018, 11:41 AM
Etabeta1🇮🇹
Etabeta1🇮🇹 - avatar
0
#include <iostream> using namespace std; int main() { float x, y; char morgan; string next; do { cout << "Input any number, arithmetic operator, any number: \n"; cin >> x >> morgan >> y; switch(morgan) { case '*': cout << x * y << endl; break; case '/': cout << x / y << endl; break; case '+': cout << x + y << endl; break; case '-': cout << x - y << endl; break; case '=': if (x == y) { cout << "True \n"; break; } else { cout << "False \n"; break; } /* case '%': cout << x % y; break; */ } cout << "You wont to continue? (yes/no) \n"; cin >> next; } while(next == "yes"); return 0; }
3rd Nov 2018, 11:44 AM
Igor The Golden Fish
Igor The Golden Fish - avatar