Here is my code : (My logic might be kind of weird)
The weird thing is that,I have commented out a cout line.If I uncomment that line,I get the right answer but commenting it gives the wrong answer.How is this even possible? Its just a printing statement.
I don’t understand.
EDIT:Using scanf("%c",&str); doesn’t work either.
store the complete expression in a string, store s[0](first number) in temp = s[0]-‘0’;
start a loop from (i=2 to l && str[i]!= ‘=’;i+=2 ) compare each character if encountered {’+’,’-’,’*’,’/’} evaluate by subtracting 48 or ‘0’ from str[i+2] and display the output.
So I guess the result is that scanf was having trouble reading my input and cin wins in this case.
Thanks.
But the question is,why is commenting and uncommenting the cout line giving different outputs?
That’s weird.