Hi guys, im having an issue by creating a calculator. I'm an absolute beginner since I just started learning Programming some days ago. Can someone tell me what's wrong in this code?
#include <cstdlib>
#include <iostream>
usingnamespace std;
int addition(int num1, int num2)
{
return num1 + num2;
}
int subtraction(int num1, int num2)
{
return num1 - num2;
}
int multiplication(int num1, int num2)
{
return num1 * num2;
}
int division(int num1, int num2)
{
return num1 / num2;
}
int main()
{
int number1;
int number2;
//Addition
cout << "You are adding. Enter the first number you would like to add. \n Number 1: ";
cin >> number1;
cout << " Enter the second number. \n Number 2: ";
cin >> number2;
cout << " The answer is: " << addition(number1, number2) << endl;
//Subtraction
cout << "You are subtracting. Enter the first number you would like to subtract. \n Number 1: ";
cin >> number1;
cout << " Enter the second number. \n Number 2: ";
cin >> number2;
cout << " The answer is: " << subtraction(number1, number2) << endl;
//Multiplication
cout << "You are adding. Enter the first number you would like to multiply. \n Number 1: ";
cin >> number1;
cout << " Enter the second number. \n Number 2: ";
cin >> number2;
cout << " The answer is: " << multiplication(number1, number2) << endl;
//Division
cout << "You are dividing. Enter the first number you would like to divide. \n Number 1: ";
cin >> number1;
cout << " Enter the second number. \n Number 2: ";
cin >> number2;
cout << " The answer is: " << division(number1, number2) << endl;
}
When I run it, it prints : 10Press
That is quite odd. Have you compiled it? Maybe you are running your previous program. And when posting code, please select it and press the <> button (then it gets formatted).
yes, I noticed that when compiling in Bloodshed Dev C++. When I tried in Visual C++ Express, it didn't show any error, and the result was different from Bloodshed Dev C++.
Bloodshed Dev C++ worked properly
Visual C++ 2010 Express did not work properly.. i don't know why.
I mean that everything that shows in the console is :