C++ Cash Register Help

This is a discussion on C++ Cash Register Help within the C++ Programming forums, part of the General Programming Boards category; I am building a program as a cash register that uses rocks, stones, and pebbles as currency. I seem to ...

C++ Cash Register Help

I am building a program as a cash register that uses rocks, stones, and pebbles as currency. I seem to be having problems converting/getting change. This is more of an arithmetic problem rather than a crash or error but if anyone could help out I'd appreciate it.

A quick test shows that once my suggestions are implemented, the output that you expected is shown.

By the way, each include must be on its own line, i.e., this:

Code:

#include <iostream>#include <string>

should be:

Code:

#include <iostream>
#include <string>

Originally Posted by nealw

that just simplified and cleaned my program up.

Actually, my compiler reminded me that your overly complex expression has a bigger problem: it results in undefined behaviour. The reason is that you are changing totalChange twice in an expression when you are only allowed to change it once.