I'm trying to solve this easy problem from SPOJ. http://www.spoj.com/problems/ARITH2/ Here is my code : (My logic might be kind of weird) http://ideone.com/upiUY8 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. asked 04 Dec '14, 22:48 ![]()
|
here is your updated code :) or answered 05 Dec '14, 00:52 ![]()
|
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. answered 05 Dec '14, 01:40 ![]()
u should have done scanf(" %c",&str) after scanning num1 as u can see there are spaces between each number and operator. :) you can read more at http://www.geeksforgeeks.org/scansets-in-c/
(05 Dec '14, 02:11)
|