So basically I must make it work with multiplication as well with signs.For example 2*2=4 but 2*-2=-4 and i cant find a proper way to do it.Any advice would be helpful.My code so far is :
#include <stdio.h>
#include <stdlib.h>
int main ( void )
{
int result = 0, val = 1, ch, howmany = 1, number = 0;
while ( ( ch = getchar() ) != EOF )
{
if ( ch == ' ' || ch == '\t' )
continue;
else if ( ( ch >= '0' ) && ( ch <= '9' ) )
number = number * 10 + ( ch - '0' );
else if ( ch == '+' )
{
result += ( number * val );
val = 1;
number = 0;
}
else if ( ch == '-' )
{
result += ( number * val );
val = -1;
number = 0;
}
else if ( ch == '\n' )
{
howmany++;
result += ( number * val );
printf( "%d\n", result);
number = 0;
result = 0;
val = 1;
}
}
}