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.
Below the code I put some examples.
Code:
#include <iostream>#include <string>
#include <iomanip>
const int PEBBLES_PER_ROCK = 25;
const int PEBBLES_PER_STONE = 5;
const int COST_COFFEE = 27;
const int COST_DONUT = 23;
using namespace std;
int main () {
int coffee = 0,
donuts = 0,
rocks = 0,
stones = 0,
pebbles = 0;
int totalPrice = 0,
totalPayment = 0,
totalChange = 0,
totalRocks = 0,
totalStones = 0,
totalPebbles = 0;
int changeRocks = 0,
changeStones = 0,
changePebbles = 0;
char junk;
cout << "Enter your order => " << endl;
cin >> coffee >> junk >> donuts >> junk >> rocks >> junk
>> stones >> junk >> pebbles;
cout << "Cups of Coffee: " << coffee << endl;
cout << "Donuts Purchased: " << donuts << endl;
totalPrice = coffee * COST_COFFEE + donuts * COST_DONUT;
totalRocks = totalPrice / PEBBLES_PER_ROCK;
totalPrice = totalPrice %= PEBBLES_PER_ROCK;
totalStones = totalPrice / PEBBLES_PER_STONE;
totalPrice = totalPrice %= PEBBLES_PER_STONE;
totalPebbles = totalPrice;
cout << "Total Bill: " << totalRocks << " rocks "
<< totalStones << " stones " << totalPebbles << " pebbles " << endl;
cout << "Cash tendered: " << rocks << " rocks " << stones << " stones "
<< pebbles << " pebbles " << endl;
totalPayment = rocks * PEBBLES_PER_ROCK + stones * PEBBLES_PER_STONE + pebbles;
totalPrice = totalRocks * PEBBLES_PER_ROCK + totalStones * PEBBLES_PER_STONE
+ totalPebbles;
totalChange = totalPayment - totalPrice;
changeRocks = (totalPayment - totalPrice) / PEBBLES_PER_ROCK;
totalChange = totalChange %= PEBBLES_PER_ROCK;
changeStones = (totalPayment - totalPrice) / PEBBLES_PER_STONE;
totalChange = totalChange %= PEBBLES_PER_STONE;
changePebbles = totalChange;
cout << "Change: " << changeRocks << " rocks " << changeStones << " stones "
<< changePebbles << " pebbles " << endl;
return 0;
}
Now *when running the programming* enter the order in c,d:r|s|p
c=coffee
d=donuts
r=rocks
s=stones
p=pebbles
ex. 3,4:7|0|3
should result in 0 rocks 1 stones 0 pebbles in change.
I do get that one right, however I get this one wrong:
1,1:0|0|80
should result in 1 rocks 1 stones 0 pebbles in change.
but I get 1 rocks 6 stones 0 pebbles.