how to make a basic calculator

I know you guys are gonna laugh but this is all I could come up with. it succeeded but doesn't work though. I have a feeling i need to put in a loop in here but not sure where to go with it. What the hell am I doing wrong?

#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main()


{
double number;
double calculation;
double multiply;
double divide;
double subtract;
double add;
double sum;

calculation = number*number;
calculation = number/number;
calculation = number-number;
calculation = number+number;

sum = calculation;

cout<<"Enter Calculation"<< endl;
cin>> calculation;
cout<<sum<<endl;

return 0;
}

Thanks Guys!!!
1) Use code tags when posting on the forum: http://cplusplus.com/forum/articles/16853/

2) You never give 'number' a value. Did you mean to get this number from the user?

3) You set 'calculation' to 4 different things. Each time you set it, you erase its previous value.

4) You set calculation again to take whatever the user inputs (erasing your previous calculation)


What exactly do you want this program to do? Break it down into smaller steps and focus on each step at a time.
And you've declared each operation (multiply, divide, etc) as a variable. Shouldn't those be functions?
thanks for the info guys - I learned my problem is in my initialization process!!
closed account (y8h7M4Gy)
Here is something I just wrote up. Basicly type a number, press enter, type another number, and it says what the sum is. It should be easy to make options whether to do addition, subtraction, ect.

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main () {
	int a,b;
	cin >> a;
	cin >> b;
	cout << a+b << endl;
	return 0;
}
Last edited on
Topic archived. No new replies allowed.