function call.

Hi all. I was wondering if I could get some advice on a program im working on.
I need to write a program that tells what coins to give out for any amount of change from 1 cent to 99 cents and i have to use this function without modification. void compute_coin(int coin_value, int& number, int& amount_left).

I can write the program fine, but I cant get my mind around how to use only the varibales my teacher is using to get it to work. here is the working code for the program as it stands.


// Include Section
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
// Main Program
int main( )
{
// Constant Declarations


// Variable Declations
int coin_value;
int quarters;
int dimes;
int nickles;
int pennies;
int total_amount;
char yes = 'y';
char Yes = 'Y';
char agian;

// Output Identification
system("CLS");
cout << " Take home #8 \n .\n";
cout << " coin counting program.\n";
cout << " \n";


// Enter code below

do
{
quarters = 0;
dimes = 0;
nickles = 0;
pennies = 0;


cout<< " Enter the amount of change ";
cin >> coin_value;
cout << "\n";

if (coin_value >= 25 && coin_value <= 100)
{
quarters = coin_value / 25;
coin_value = coin_value % 25;
}


if (coin_value <= 24 && coin_value >= 10)
{
dimes = coin_value /10;
coin_value = coin_value % 10;
}


if (coin_value <= 9 && coin_value >= 5)
{
nickles = coin_value / 5;
coin_value = coin_value % 5;
}


if (coin_value <= 4 && coin_value >= 1)
{
pennies = coin_value;
}


////////
total_amount =( quarters * 25)+ (dimes * 10)+ (nickles * 5) + pennies;
cout << total_amount << " Cents Can be given as " ;
////////


if (quarters == 1)
{
cout << quarters << " quarter, ";
}


if (quarters == 2 || quarters == 3)
{
cout << quarters << " quarters, ";
}


if (dimes == 1)
{
cout << dimes << " dime, ";
}


if (dimes == 2 )
{
cout << dimes << " dimes, ";
}


if (nickles == 1 )
{
cout << nickles << " nickle, ";
}


if (pennies == 1)
{
cout << pennies << " penny. " << endl;
}


if (pennies < 4 && pennies > 2)
{
cout << pennies << " pennies. " << endl;
}


cout << "\n";
cout << " Would you like to run the program agian (Y or N)? ";
cin >> agian;

}


while (agian == yes || agian == Yes);

cout << "\n\nEnd Program.\n";
return 0;
}
I really don't know how, but it is a well made program.
good luck!
closed account (z05DSL3A)
1
2
3
4
5
6
7
8
9
10
const int valueOfQuarter =25;
const int valueOfDime =10;

int quarters = 0;
int dimes = 0;

int amount_left = 99; //from user

compute_coin(valueOfQuarter , quarters , amount_left);
compute_coin(valueOfDime , dimes , amount_left);


Dose that help?
Topic archived. No new replies allowed.