# Change calculator

I likes my use of functions so I'm mostly looking for little things but if you see something tell me :)

#include <iostream>

using namespace std;

bool quarterValid(double num, const double finalNum); bool dimeValid(double num, const double finalNum); bool nikleValid(double num, const double finalNum); bool pennieValid(double num, const double finalNum);

class change {
public:
change() = default;
change(double a) { setChange(a); }
void getChange();
void setChange(double change) { totalAmmount = change; }
int getQuaters() const { return ammountQuarters; }
int getDimes() const { return ammountDimes; }
int getNikles() const { return ammountNikles; }
int getPennies() const { return ammountPennies; }
private:
double totalAmmount; double ammountSoFar = 0;
int ammountQuarters = 0, ammountDimes = 0, ammountNikles = 0, ammountPennies = 0;
};

void change::getChange() {
while (quarterValid(ammountSoFar, totalAmmount)) {
++ammountQuarters;
}
while (dimeValid(ammountSoFar, totalAmmount)) {
++ammountDimes;
}
while (nikleValid(ammountSoFar, totalAmmount)) {
++ammountNikles;
}
while (pennieValid(ammountSoFar, totalAmmount)) {
++ammountPennies;
}
}

num += .25;

num += .10;
}
num += .05;
}
num += .01;
}

bool quarterValid(double num, const double finalNum) {
if ((num + .25) <= finalNum)
return true;
return false;
}

bool dimeValid(double num, const double finalNum) {
if ((num + .10) <= finalNum)
return true;
return false;
}

bool nikleValid(double num, const double finalNum) {
if ((num + .05) <= finalNum)
return true;
return false;
}

bool pennieValid(double num, const double finalNum) {
if ((num + .01) <= finalNum)
return true;
return false;
}

• Don't use double for monetary values. Use integer types just make it multiples of the smallest denomination (ie in US use cents). – Martin York Dec 31 '15 at 16:14

### Floating point math

Floating point math is annoying and imprecise. It'd be better to avoid it entirely. Convert your values to an integral number of cents up front:

int cents = amount * 100;


And then decrease/divide by 25, 10, 5, and 1 instead.

### Spelling

The coins are a nickel and a penny, not nikle and pennie.