### 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

 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 #include 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; } system("pause"); return 0; #include 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; 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:

 1234567891011121314151617181920212223242526272829303132333435363738 #include using namespace std; int main() { int dollars,bills; char x; cout <<"This program will convert dollars into denominational bills."<> 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.