i wrote a simple program in C to perform a series of arithmetic operations as we do in our scientific calculators and at last get the output. the program executes but i'm not getting the expected result. plz help.
Code:
#include<stdio.h>
#include<conio.h>

float answer(float a, char op, float b)
{
	float res;
	switch(op)
	{
		case '+': res=a+b; break;
		case '-': res=a-b; break;
		case '*': res=a*b; break;
		case '/': {
				if(b!=0)
					res=a/b;
				else
					printf("math error\n");
			  } break;
	}
	return res;
}

void main()
{
	float a, b, c;
	char op;
	clrscr();
	scanf("%f %c %f",&a, &op, &b);

	while(b!='\n')
	{
		c=answer(a, op, b);
		a=c;
		scanf("%c %f", &op, &b);
	}
	printf("the result is %f\n", c);
	getch();
}

Last edited by shabbir; 22May2008 at 15:22.. Reason: Code block