I am supposed to design a Calculator on C++ that works like an actual calculator(starts with 0 and values keyed in are added to the sum.) However, when i try to code this, the value does not add upon itself or subtracts. it resets to its initialised value each time(0). Here is the code.
basically, what i need is for it to work like a real calculator which stores the values of what was previously keyed in. And exits upon user pressing "=".
void getInfo(char& x, double & y)
{
char equal;
double result = 0; // Note: initialize it to 0
int sum1,sum2,sum3; // I don't know why you want three of them?
cout << "==> " << y << endl << endl;
while (equal != '=')
{
cin >> x >> y; // here you reset x and y
if (x =='+')
{
y=y; // no effect
sum1=y+y; // neither this
result += y; // add y to the result
cout << "==>" << y result << endl << endl; // show the result
}
elseif(x =='-')
{
y=y-y;
result -= y; // subtract y from the result
cout << "==>" << y result << endl << endl;
}
...
I don't see the use of the parameter char& x, double & y. When you call getInfo on line 23 x is unitialized and contains a random value.