0

I am trying to make a calculator, but it is being weird for no apparent reason.

Whatever I do, the answers are nothing like they are supposed to be. If I enter this into the "seems like this program requires input" box, num1= 10; num2 = 10; It says this: Added: -2 Subtracted: 2 Divided: 0 Added: 0 Why is it doing this? And if I just enter 10, then it does this: Multiplied: -20 Divided: -5 Added: 8 Subtracted: 12 Here is the code: /* This is my C++ calculator Here are the abilites and how to use them: Addition: Type them in like this: X+Y So if I wanted to add 10 and 6, I would type it in like this: 10+6 Then the program would output 16 For subtraction, replace the + with a -. For multiplication, enter the same, but instead of a +, use a *. For 10 times 6, I would enter this: 10 6 That would output 60. For division, replace the * with a /. Now for some slightly more complicated stuff: Modulus: AKA the % sign Type in your numbers like so: X % Y, no need for spaces, but they are OK. Square root: Type in this first: sqrt() Then, inside the (), put in your number. sqrt(25) Outputs 5 You can also put in an entire exression if you want to. sqrt(5*5*5*5) Outputs 25 Then trigonometry: cos(numbers) sin(numbers) tan(numbers) */ #include <iostream> #include <cmath> using namespace std; int main() { int num1; int num2; int mul; int divi; int add; int sub; cin >> num1 >> num2; mul=num1*num2; divi=num1/num2; add=num1+num2; sub=num1-num2; cout << "Multiplied: \n" << mul << endl; cout << "Divided: \n" << divi << endl; cout << "Added: \n" << add << endl; cout << "Subtracted: \n" << sub << endl; return 0; } Link to code: https://code.sololearn.com/c8Ly51qF2rz3/#cpp

14th Dec 2017, 2:29 AM
The Most Awesomest Peson
The Most Awesomest Peson - avatar
6 Answers
+ 2
Lol dude, you have to enter the input for the program to use, not actual code. Your program expects 2 inputs ( cin >> num1 >> num2; ) So you have to enter 2 numbers. In this case you can seperate them by spaces or by newlines. Try to enter 10 5 for example. If you enter only 1 number it only writes to the num1 and num2 gets garbage.
10th Dec 2017, 5:21 PM
Dennis
Dennis - avatar
0
It is easier for you to get help, if you put code into playground (even if it doesn't run here) followed by linking it to your post.
10th Dec 2017, 5:19 PM
John Wells
John Wells - avatar
0
you should enter: 10 10 to the box. Are you actually putting num1 etc. in there?
10th Dec 2017, 5:22 PM
John Wells
John Wells - avatar
0
It runs fine for me with good inputs.
10th Dec 2017, 5:31 PM
John Wells
John Wells - avatar
0
Lol I was entering real code, and such like: "10*10" and I couldn't figure out how to input correctly. Thanks all!
14th Dec 2017, 2:31 AM
The Most Awesomest Peson
The Most Awesomest Peson - avatar
0
You could do the real math formulas, but would have to change the input method.
14th Dec 2017, 2:36 AM
John Wells
John Wells - avatar