+ 1
What is wrong with this case?
case '%': cout << x % y; break;
4 Réponses
+ 3
% only works or integers, but x and y are float in your code
You should cast them in this case.
+ 1
Thanks)
0
write the link of the entire code
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;
}