Code giving wrong answers : 30 * 10 = 150 and 10 * 10 = - 350 please help >.< | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Code giving wrong answers : 30 * 10 = 150 and 10 * 10 = - 350 please help >.<

First c++ program ive written by myself to estimate net pay for paychecks. https://code.sololearn.com/cK8ar3L0pSK9/?ref=app

1st Aug 2020, 10:39 AM
Macathain
Macathain - avatar
3 Answers
+ 5
Macathain , please include programming language in tags when you post a question here. Thanks!
1st Aug 2020, 11:11 AM
Lothar
Lothar - avatar
+ 1
h = hr - 40; if I worked 20 hours h = 20 - 40 = -20 So the number of hours that are worked become negative and then the next equations als get a negative value. It probably should be h = 40 - hr;
1st Aug 2020, 11:26 AM
sneeze
sneeze - avatar
+ 1
So h = 40 - hr; didnt work.. i found out that, as you said, it was the h calculation that was messin it up. but it was because i had defined it outside of the func. So i changed the value to 0 and just redefined it inside the func. Seems to work well now since i transfered the stack of var defs into the if func. I transfered the stack because i was still havimg issues getting the right answer for the overtime. Thanks guys!
1st Aug 2020, 1:42 PM
Macathain
Macathain - avatar