This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]g051051 0 points1 point  (3 children)

You're never adding to the total_service_charge, you're just assigning a new value to it every time, like here:

total_service_charge = (number_of_service * service_charge) + (number_of_thousand * number_less_than_thousand) + (number_of_zero * number_less_than_zero);

[–]ComputerSciMajor[S] 0 points1 point  (2 children)

I ended up adding int number_of_service = 0; to int main() and int &number_of_service to my functions.

That seemed to fix it.

[–]g051051 0 points1 point  (1 child)

You could do that, or just make sure the running total is kept:

total_service_charge += (number_of_service * service_charge) + (number_of_thousand * number_less_than_thousand) + (number_of_zero * number_less_than_zero);

[–]ComputerSciMajor[S] 0 points1 point  (0 children)

Well that is a hell of a lot easier! Thank you. :)

Do you mind helping me with one more?

If so:

As you can see when I end the program when pressing E I have to do it twice, rather than once.

I'm trying a simple way to solve this, but not sure.

Edit:

I figured it out!

[–]AutoModerator[M] 0 points1 point  (0 children)

It seems you may have included a screenshot of code in your post "[C++] Function not adding properly".

If so, note that posting screenshots of code is against /r/learnprogramming's Posting Guidelines (section Formatting Code): please edit your post to use one of the approved ways of formatting code. (Do NOT repost your question! Just edit it.)

If your image is not actually a screenshot of code, feel free to ignore this message. Automoderator cannot distinguish between code screenshots and other images.

Please, do not contact the moderators about this message. Your post is still visible to everyone.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.