My code is part of a calculator program. it computes
4
*
4
E
and then gives the answer 16 which is correct but if i do more than 2 numbers, the answer is completely wrong giving crap. why does it work for 2 integers but anything more it doesnt? here is my code:
#include <stdio.h>
#define SIZE 100
int main()
{
int a[SIZE];
char b[SIZE];
int i = 1;
int k = 1;
char c = 'a';
int total;
while (c != 'E' )
{
scanf("%d", &a[i]);
fflush(stdin);
scanf("%c", &b[i]);
fflush(stdin);
c = b[i];
i++;
}
a[SIZE] = i - 1;
b[SIZE] = i - 1;
for(i=1;i <= b[SIZE]; i++)
{ if(b[i] == '*')
{ a[i]=a[i]*a[i+1];
a[SIZE] -= 1;
b[SIZE] -= 1;
for(k=i+1;k<= a[SIZE]; i++)
a[i]=a[i+1];
for(k=i+1;k<= b[SIZE] ;i++)
b[i]=b[i+1];
}
printf("the answer is: %d\n", a[i]);
}
}



LinkBack URL
About LinkBacks



