Is there a shorter way of dong this | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is there a shorter way of dong this

I am not supposed to get a negative number in the end is there a way to make it so if I get a negative number it changes it to positive? Instead of writing if (agemonth == -1) { cout << 1} for every number?

30th Sep 2018, 4:07 AM
StormIncoming
3 Answers
+ 3
if(agemonth < 0) cout << -agemonth;
30th Sep 2018, 5:27 AM
Anna
Anna - avatar
+ 1
Just use unsigned int.
30th Sep 2018, 4:48 AM
Sergey Ushakov
Sergey Ushakov - avatar
0
Jay Matthews I am not sure but somewhere I read that mod with negative is implementation defined and hence it behaves differently for different compiler... No offense but want to make this understanding clear for me..
30th Sep 2018, 7:28 AM
Ketan Lalcheta
Ketan Lalcheta - avatar