calculator with multiple operands

my code in addition is correct but in subtraction,multiplication and division is wrong :(

#include<iostream>
#include<conio.h>
using namespace std;
void addition(int *op)
{
int x,z=0,temp;
cout << "Number of operands: ";
cin >> x;
for(int i=1;i<=x;i++)
{
cout << "Enter " << i << "st " << "operand: ";
cin >> z;
*op = *op + z;
}
}
void subtraction(int *op)
{
int x,z=0,temp;
cout << "Number of operands: ";
cin >> x;
for(int i=1;i<=x;i++)
{
cout << "Enter " << i << "st " << "operand: ";
cin >> z;
*op = *op - z;
}
}
void multiplication(int *op)
{
int x,z=0,temp;
cout << "Number of operands: ";
cin >> x;
for(int i=1;i<=x;i++)
{
cout << "Enter " << i << "st " << "operand: ";
cin >> z;
*op = *op * z;
}
}
void division(int *op)
{
int x,z=0,temp;
cout << "Number of operands: ";
cin >> x;
for(int i=1;i<=x;i++)
{
cout << "Enter " << i << "st " << "operand: ";
cin >> z;
*op = *op / z;
}
}
int main()
{
char ans;
int op=0;

cout << "+ Addition" << endl;
cout << "- Subtraction" << endl;
cout << "* Multiplication" << endl;
cout << "/ Division" << endl << endl;

cout << "Choose an option: ";
cin >> ans;

switch(ans)
{
case '+':
addition(&op);
cout << "The Product is " << op;
break;
case '-':
subtraction(&op);
cout << "The Product is " << op;
break;
case '*':
multiplication(&op);
cout << "The Product is " << op;
break;
case '/':
division(&op);
cout << "The Product is " << op;
break;
default:
cout << "Invalid option";
}


getch();
return 0;
}
All your computations starts from zero. 0 * a * b * c.... will always be 0. Same situation with division.
Topic archived. No new replies allowed.