Change program, issues.

i rewrote my program a bit, but it still is kinda freaking out.
but at least i dont have the errors anymore. unfortunetly my progam doesnt run right after the quaters. and i always have an extra penny.

//this program calculates the number of quarters,
// dimes and nickles and pennies are nessasary to
//generate the number of cents imputed
#include <iostream.h>
#include<string.h>

main()
{
double toBeChanged;
int numberOfDimes, numberOfQuarters, numberOfNickels, numberOfPennies;
cout << " I will show you how many quarters, dimes, nickels, and \npennies needed to make the amount. \nHow much money do you have? (i.e. 1.25)" << '\n';
cin >> toBeChanged;

cout << "For "<< toBeChanged << " you will need:"<<'\n';

toBeChanged = toBeChanged * 100;

if(toBeChanged >= 25)
{
numberOfQuarters = (toBeChanged / 25);
toBeChanged = (int)toBeChanged % 25;
}

if(toBeChanged >= 10)
{
numberOfDimes = (toBeChanged / 10);
toBeChanged = (int)toBeChanged % 10;
}

if(toBeChanged >= 5)
{
numberOfNickels = (toBeChanged / 5);
toBeChanged = (int)toBeChanged % 5;
}

if(toBeChanged >= 1)
{
numberOfPennies = (toBeChanged / 1);
toBeChanged = (int)toBeChanged % 1;
}


cout << numberOfQuarters<< " quarters,"<<'\n';
cout << numberOfDimes << " dimes, "<< '\n';
cout << numberOfNickels << " nickels,"<< '\n';
cout << numberOfPennies << " pennies."<< '\n';

system("pause");
return 0;
}




so, it can get the quarters right, but then it messes up on the dimes and below.
any help?
Try declaring the variable values at the beginning.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//this program calculates the number of quarters,
// dimes and nickles and pennies are nessasary to
//generate the number of cents imputed
#include <iostream>
#include <string>

int main()
{
        double toBeChanged;
        int numberOfDimes = 0, numberOfQuarters = 0, numberOfNickels = 0, numberOfPennies = 0;
        std::cout << " I will show you how many quarters, dimes, nickels, and \npennies needed to make the amount. \nHow much money do you have? (i.e. 1.25)" << '\n';
        std::cin >> toBeChanged;

        std::cout << "For "<< toBeChanged << " you will need:"<<'\n';

        toBeChanged = toBeChanged * 100;

        if(toBeChanged >= 25)
        {
                numberOfQuarters = (toBeChanged / 25);
                toBeChanged = (int)toBeChanged % 25;
        }

        if(toBeChanged >= 10)
        {
                numberOfDimes = (toBeChanged / 10);
                toBeChanged = (int)toBeChanged % 10;
        }

        if(toBeChanged >= 5)
        {
                numberOfNickels = (toBeChanged / 5);
                toBeChanged = (int)toBeChanged % 5;
        }

        if(toBeChanged >= 1)
        {
                numberOfPennies = (toBeChanged / 1);
                toBeChanged = (int)toBeChanged % 1;
        }

        std::cout << numberOfQuarters<< " quarters,"<<'\n';
        std::cout << numberOfDimes << " dimes, "<< '\n';
        std::cout << numberOfNickels << " nickels,"<< '\n';
        std::cout << numberOfPennies << " pennies."<< '\n';

        return 0;
}


G00d luck
Topic archived. No new replies allowed.