0
the program does not work, can anyone help? Or show how you can do better? (This is a calculator with the ability to subtract or
#include <iostream>; using namespace std; int main() { int x; int num; int numb; int y; cin >> num; cin >> x; cin >> numb; if (x = x) { y = num - numb; } else ( y = num + numb); cout << "Answer=" << y << endl; }
2 Antworten
+ 6
What should be the value of x? if(x=x) is a wrong way to check condition. Use if (x == some_value)
The following code will do subtraction if x is 1, it'll perform addition otherwise.
Sample input:
12 1 4
answer: 8
12 3 4
answer: 16
(note: the 2nd input is x)
https://code.sololearn.com/cGd6V1Iu3DQ0/?ref=app
+ 2
https://code.sololearn.com/c8wUuxNq8YhZ/?ref=app