// Lab 6                              
// This program tells what coins to give out for any amount of change
// from 1 cent to 99 cents using three coin denomination: quarters, dimes, and
// pennies.

#include <iostream>
#include <fstream>

// function declarations
istream &getData(istream &is, double &amount);
void displayResults(ostream & os, double numberCoins, numbCoins, nCoins);  
void computeCoins(int coinValue, int & numberCoins, int & amount); 

using namespace std;
	
int main()
{  
    double amount, coinValue, quarterCoins, dimeCoins, pennyCoins;
    ifstream fin;
    fin.open("readlab6.in");
    if (fin.fail())
    {
       cerr << "error opening input file. \n\n";
       system("pause");
       exit(1);
    }
    ofstream fout;
    fout.open("outputlab6.out");
    if (fout.fail())
    {
       cerr << "error opening output file.\n\n";
       system("pause");
       exit(1);
    }
    
   	cout.setf(ios::fixed);
	cout.precision(2);
 
    fout << "Lab 6              \n";
    
   	while (getData(fin, amount)
   	    (0 < coinValue <= 25, 0 < amount < 100);
  		computeCoins(25, & numberCoins, & amount);
	    displayResults(cout, quarterCoins, dimesCoins, pennyCoins);
		else
			cout << "\nError in calcuation"<< endl;
 
     fin.close()
     system("pause");
     return (0) 
     
//function definition for input
istream & getData(istream & is, double amount)
{
	if (is == cin)
        cout << "Enter the amount of change: ";
	is >> amount;
	return is;
}
//function definition to calculate number of coins
void computeCoins(int coinValue, int & numberCoins, int & amount)
{
     double numberCoins, dimeCoins, pennyCoins;
// unknown where I put precondition(0 < coinValue <= 25, 0 < amount < 100
     numberCoins = amount/coinValue;
     if (amount > numberCoins *25)
         {
                numCoins = (amount - (numberCoins * .25))/10;
                nCoins = amount - numberCoins * .25 + numCoins * .10;
         }
     else 
          nCoins = amount - numberCoins * .25);
              
            fout << "The number of  is:  " << numberCoins;
}
//function definition for output
void displayResults(ostream & os, double quarterCoins, dimeCoins, pennyCoins); 
{
	os << "\nThe number of quarters: " << numberCoins << endl;
		 << "The number of dimes" << numbCoins << endl;
		 << "The number of pennies" << nCoins << endl;
}

I don't have my crystle ball with me at the moment, so please describe the problem with your program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.