Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//main.cpp //header files #include <iostream> #include <cmath> int main() { // d

ID: 3668347 • Letter: #

Question

//main.cpp

//header files

#include <iostream>

#include <cmath>

int main()

{

// declare variables

float price;

float money_given;

float ReturnChange;

float PrintDenomination;

// asking user to enter cost

std::cout << "Enter the price of the item: $";

std::cin >> price;

// asking user to enter money given

std::cout << "Enter the money tendered: $";

std::cin >> money_given;

std::cout << " ";

// call function

ReturnChange; price; money_given;

return 0;

}

// header files

#include <cmath>

#include <iomanip>

#include <iostream>

// Static functions:

namespace

{

// This static function prints the amount of a given denomination (bill or coin).

void PrintDenomination( unsigned int amount, double denomination );

// This static function prints the amount of a given denomination (bill or coin).

void PrintDenomination( unsigned int amount, double denomination )

{

if( amount == 0 )

{

return;

}

std::cout << amount ;

if( denomination == 100 )

{

std::cout << " $100 bill";

}

else if( denomination == 50 )

{

std::cout << " $50 bill";

}

else if( denomination == 20 )

{

std::cout << " $20 bill";

}

else if( denomination == 10 )

{

std::cout << " $10 bill";

}

else if( denomination == 5 )

{

std::cout << " $5 bill";

}

else if( denomination == 2 )

{

std::cout << " $2 bill";

}

else if( denomination == 1 )

{

std::cout << " $1 bill";

}

else if( denomination == 0.25 )

{

std::cout << " $0.25 bill";

}

else if( denomination == 0.10 )

{

std::cout << " $0.10 bill";

}

else if( denomination == 0.05 )

{

std::cout << " $0.05 bill";

}

else if( denomination == 0.01 )

{

if( amount == 1 )

{

std::cout << " $0.01 bill";

}

else

{

std::cout << " penies";

}

}

else

{

std::cout << "Error: PrintDenomination() was given an invalid "

<< "denomination ("

<< denomination

<< "). Bugfix required. ";

exit( 2 );

}

if( amount > 1 && denomination != 0.01 )

{

std::cout << "s";

}

std::cout << " ";

return;

}

} // Unnamed namespace

// This function displays the change necessary, if any, for a given purchase.

void ReturnChange( double price, double money_given )

{

if( price <= 0 )

{

std::cout << "Error: That is not a valid price. ";

exit( 1 );

}

else if( money_given < 0 )

{

std::cout << "That is not a valid amount for money given. ";

exit( 1 );

}

double change = money_given - price;

if( change == 0 )

{

std::cout << "Exact change. ";

}

else if( change < 0 )

{

change = 0 - change;

std::cout << "Not enough money was tendered; $";

std::cout << std::setprecision(2); // Prints only two decimal places

std::cout << std::fixed;

std::cout << change;

std::cout << " more is required. ";

}

else

{

std::cout << "The change is $";

std::cout << std::setprecision(2); // Prints only two decimal places

std::cout<< std::fixed;

std::cout << change;

std::cout << ", which is: ";

double denominations[11] = { 100, 50, 20, 10, 5, 2, 1, 0.25, 0.10, 0.05, 0.01 };

unsigned int leftover;

unsigned int coins_bills;

for( int i = 0; i < 11; i++ )

{

// Sets coins_bills to be the necessary amount of a specific denomination,

// and sets change to the remaining change to be calculated.

leftover = std::fmod( change, denominations[i] );

coins_bills = ( change - leftover ) / denominations[i];

change -= coins_bills * denominations[i];

PrintDenomination( (coins_bills), denominations[i] );

}

}

return;

}

//change.hpp

#pragma once

// This function displays the change necessary, if any, for a given purchase.

void ReturnChange( double price, double money_given );

i dont know where the mistake is when i debug it, it only says

Enter price of the item:

Enter the money tendered:

press any key to continue .....

Explanation / Answer

//main.cpp

//header files

#include <iostream.h>

#include <cmath.h>

int main()

{

// declare variables

float price;

float money_given;

float ReturnChange;

float PrintDenomination;

// asking user to enter cost

std::cout << "Enter the price of the item: $";

std::cin >> price;

// asking user to enter money given

std::cout << "Enter the money tendered: $";

std::cin >> money_given;

std::cout << " ";

// call function

ReturnChange( price,money_given);

return 0;

}

// header files

#include <cmath.h>

#include <iomanip.h>

#include <iostream.h>

// Static functions:

namespace

{

// This static function prints the amount of a given denomination (bill or coin).

void PrintDenomination( unsigned int amount, double denomination );

// This static function prints the amount of a given denomination (bill or coin).

void PrintDenomination( unsigned int amount, double denomination )

{

if( amount == 0 )

{

return;

}

std::cout << amount ;

if( denomination == 100 )

{

std::cout << " $100 bill";

}

else if( denomination == 50 )

{

std::cout << " $50 bill";

}

else if( denomination == 20 )

{

std::cout << " $20 bill";

}

else if( denomination == 10 )

{

std::cout << " $10 bill";

}

else if( denomination == 5 )

{

std::cout << " $5 bill";

}

else if( denomination == 2 )

{

std::cout << " $2 bill";

}

else if( denomination == 1 )

{

std::cout << " $1 bill";

}

else if( denomination == 0.25 )

{

std::cout << " $0.25 bill";

}

else if( denomination == 0.10 )

{

std::cout << " $0.10 bill";

}

else if( denomination == 0.05 )

{

std::cout << " $0.05 bill";

}

else if( denomination == 0.01 )

{

if( amount == 1 )

{

std::cout << " $0.01 bill";

}

else

{

std::cout << " penies";

}

}

else

{

std::cout << "Error: PrintDenomination() was given an invalid "

<< "denomination ("

<< denomination

<< "). Bugfix required. ";

exit( 2 );

}

if( amount > 1 && denomination != 0.01 )

{

std::cout << "s";

}

std::cout << " ";

return;

}

void ReturnChange( double price, double money_given );

} // Unnamed namespace

// This function displays the change necessary, if any, for a given purchase.

void ReturnChange( double price, double money_given )

{

if( price <= 0 )

{

std::cout << "Error: That is not a valid price. ";

exit( 1 );

}

else if( money_given < 0 )

{

std::cout << "That is not a valid amount for money given. ";

exit( 1 );

}

double change = money_given - price;

if( change == 0 )

{

std::cout << "Exact change. ";

}

else if( change < 0 )

{

change = 0 - change;

std::cout << "Not enough money was tendered; $";

std::cout << std::setprecision(2); // Prints only two decimal places

std::cout << std::fixed;

std::cout << change;

std::cout << " more is required. ";

}

else

{

std::cout << "The change is $";

std::cout << std::setprecision(2); // Prints only two decimal places

std::cout<< std::fixed;

std::cout << change;

std::cout << ", which is: ";

double denominations[11] = { 100, 50, 20, 10, 5, 2, 1, 0.25, 0.10, 0.05, 0.01 };

unsigned int leftover;

unsigned int coins_bills;

for( int i = 0; i < 11; i++ )

{

// Sets coins_bills to be the necessary amount of a specific denomination,

// and sets change to the remaining change to be calculated.

leftover = std::fmod( change, denominations[i] );

coins_bills = ( change - leftover ) / denominations[i];

change -= coins_bills * denominations[i];

PrintDenomination( (coins_bills), denominations[i] );

}

}

return;

}

//change.hpp

#pragma once

Your mistakes are

1. Declare header files with " .h " like #include<iosteam.h>.

2.Calling function ReturnChange; price; money_given; is not correct And correct ReturnChange(price,money_given); This one is correct.

3. Declaration of function is importent where function actually declares.

please try above program for good result