Why this ptogram gives negative value for year? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why this ptogram gives negative value for year?

https://code.sololearn.com/cbUFr1ahX6mH/?ref=app

13th Mar 2021, 1:52 PM
Jawahirullah
Jawahirullah - avatar
3 Answers
+ 3
you must add i++; to line 21,22 otherwise you’ll use the ascii value of ‘/‘ but you probably already know this since you’ve done a similar thing at line 17
13th Mar 2021, 2:37 PM
Rex
Rex - avatar
+ 2
the ascii value of “/” is 47 and you subtract 48 and this is why the output is NEGATIVE ... for example if your input is “20/01/2003” (as you have commented in your code...) the output will be : -10000+2000+000+00+3 = -7997 i++; at line 22 will fix this...
13th Mar 2021, 2:50 PM
Rex
Rex - avatar
0
Stop using C-style in c++ for real
13th Mar 2021, 3:23 PM
Maher Al Dayekh
Maher Al Dayekh - avatar