ok think i got this really close to working cant figure out whats wrong!

algorithm i have to use..
// Start
// Declarations
// num dollars
// output "Please enter the a whole dollar amount (no cents!). Input 0 to terminate: "
// input dollars
// while ( dollars <> 0)
// displayBills(dollars)
// output "Please enter the a whole dollar amount (no cents!). Input 0 to terminate: "
// input dollars
// endwhile
// Stop
//
//
//
// displayBills(num dollars)
// Declarations
// num ones
// num fives
// num tens
// num twenties
// num temp
// twenties = dollars / 20
// temp = dollars % 20
// tens = temp / 10
// temp = temp % 10
// fives = temp / 5
// ones = temp % 5
// output "The dollar amount of ", dollars, " can be represented by the following monetary denominations"
// output " Twenties: ", twenties
// output " Tens: ", tens
// output " Fives: ", fives
// output " Ones: ", ones
// return

// my code with 3 errors on my compiler below

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
using namespace std;

int main()
{

int dollars;

cout<<"Please enter the a whole dollar amount (no cents!). Input 0 to terminate: ";
cin>>dollars;

while(dollars!=0){
        cout<<dollars;
        cout<<"Please enter the a whole dollar amount (no cents!). Input 0 to terminate: ";
        cin>>dollars;
}

 system("pause");



return 0; 

#include <iostream>
using namespace std;

int main()
{

int dollars;

cout<<"Please enter the a whole dollar amount (no cents!). Input 0 to terminate: ";
cin>>dollars;

while(dollars!=0){
        cout<<dollars;
        cout<<"\nPlease enter the a whole dollar amount (no cents!). Input 0 to terminate: ";
        cin>>dollars;


system("pause"); 



return 0; 

using namespace std;

int main()
{
    int dollar, bills;
    while(true)
    {
        cout << "Please type in the dollar amount, without cents, that you would like to convert to bills." << endl;
        cin >> dollar;
        if(dollar == 0)
            break;
        bills = (dollar-(dollar%20))/20;
        cout << endl << "The number of denominational bills for " << dollar << " dollars is:";//basic statement
        cout << bills;
        if (bills == 1)
            cout << " twenty, ";
        else
            cout << " twenties, ";
        dollar -= (bills*20);
        bills = (dollar-(dollar%10))/10;
               cout << bills;
        if (bills == 1)
            cout << " ten, ";
        else
            cout << " tens, ";
        dollar -= (bills*10);
        bills = (dollar-(dollar%5))/5;
        cout << bills;
        if (bills == 1)
            cout << " five, ";
        else
            cout << " fives, ";
        dollar -= (bills*5);
        cout << "and " << dollar;
        if (dollar == 1)
            cout << " one.";
        else
            cout << " ones.";
        cout << endl;
}
    return 0;
}

says i have 3 errors and im not sure if my int mains are the issue or where there placed this algorithm is complex for me to figure out.
Last edited on
You should only have one main function
Delete the first two main functions, and everything in them. Better yet, go to the third main() in that code, delete everything above it, up to and not including using namespace std;
Zmlink, excellent advice above from Yanson and Ispil. The following works well on my XP computer with code:blocks and the MinGW compiler:

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
#include <iostream>
using namespace std;
int main()
{
int dollars,bills;
char x;
        cout <<"This program will convert dollars into denominational bills."<<endl;
        cout <<"\nInput 0 to terminate or any character to continue: ";
        cin>> x;
    if (x=='0') return 0;
    else
    do {cout << "\nPlease enter the dollar amount, without cents, that you would like to convert to bills: ";
        cin >> dollars;}
    while(dollars == 0);
        bills = (dollars-(dollars%20))/20;
        cout << endl << "The number of denominational bills for " << dollars << " dollars is: ";//basic statement
        cout << bills;
        if (bills == 1) cout << " twenty, ";
        else cout << " twenties, ";
        dollars -= (bills*20);
        bills = (dollars-(dollars%10))/10;
        cout << bills;
        if (bills == 1) cout << " ten, ";
        else  cout << " tens, ";
        dollars -= (bills*10);
        bills = (dollars-(dollars%5))/5;
        cout << bills;
        if (bills == 1) cout << " five, ";
        else cout << " fives, ";
        dollars -= (bills*5);
        cout << "and " << dollars;
        if (dollars == 1) cout << " one.";
        else cout << " ones.";
        cout << endl;
        cin.get();
        cin.get();
    return 0;
}

The conversion code from dollars into denominational bills works well and solved a mystery for me as well! Cheers, Don
Last edited on
Just want to say that there is no need for this:

bills = (dollars-(dollars%20))/20;

Since dollars and 10 are both integers, the result of division is also an integer. EG 27/10 is not 2.7, but rather 2. So you can change that (and the other lines like it) to:

bills = dollars/20;
Topic archived. No new replies allowed.