0

Please tell why the answer is 101 ?

gave an string 3+2 and expected the answer 1 https://code.sololearn.com/c1oeyte23cGo/?ref=app

30th Sep 2017, 1:54 PM
Ishan
Ishan - avatar
2 odpowiedzi
+ 2
note is a string. note[0] returns a character. The ascii value for the character '3' is 51 and the ascii value for '2' is 50. 50 + 51 = 101. You should subtract the character '0' ( which has a value of 48 ) from both characters like this: cout << note[0] - '0' + note[2] - '0';
30th Sep 2017, 2:29 PM
Dennis
Dennis - avatar
0
thanku very much
30th Sep 2017, 2:30 PM
Ishan
Ishan - avatar