Calculator
Jun 12, 2015 at 3:39am Jun 12, 2015 at 3:39am UTC
I've managed to create a calculator that accepts different operators and any amount of numbers using arrays. However, it doesn't calculate the ( * and / ) before the ( + and - ) which I didn't manage to do. I'd like it to calculate the * and / first, any help would be appreciated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <new>
#include <climits>
using namespace std;
int main(int argc, char **argv)
{
double number[50] = { };
char op[50] = { };
for (int i=0; i<50; i++)
{
cout << "Enter Number" ;
cin >> number[i];
cout << "Enter Operator or \"=\"" ;
cin >> op[i];
if (op[i] == '=' )
{
break ;
}
}
double total;
total = number[0];
for (int i=0;i<50; i++)
{
if (op[i] == '*' )
{
total = total*number[i+1];
}
if (op[i] == '+' )
{
total = total+number[i+1];
}
if (op[i] == '-' )
{
total = total-number[i+1];
}
if (op[i] == '/' )
{
total = total/number[i+1];
}
}
cout << total;
}
Jun 12, 2015 at 4:19am Jun 12, 2015 at 4:19am UTC
Jun 12, 2015 at 7:26am Jun 12, 2015 at 7:26am UTC
Nice Link
Topic archived. No new replies allowed.