I am trying to write a program that can figure change. Something that might be used in a fast food setting. The Employee is simply prompted to enter the amount to be returned to the costumer and the program would tell how many dollars, quarters, dimes, ect. to be returned.
Here is what I have.
#include "stdafx.h"
#include <iostream>
using namespace std;
struct change
{
int dollars;
int quarters;
int dimes;
int nickels;
int pennies;
};
change makeChange(float money);
int main()
{
float totalMoney;
change changeAmount;
cout << "Enter the total to be returned to the customer: ";
cin >> totalMoney;
changeAmount = makeChange(totalMoney);
cout << "Give the customer "
<< changeAmount.dollars << " dollars, "
<< changeAmount.quarters << " quarters, "
<< changeAmount.dimes << " dimes, "
<< changeAmount.nickels << " nickels, and "
<< changeAmount.pennies << " pennies.\n";
change makeChange(float money)
{
change makeChange;
makeChange.dollars = static_cast<int>(money);
float remainingMoney = money - makeChange.dollars;
makeChange.quarters = static_cast<int>(remainingMoney * 4);
float remainingMoney = money - makeChange.quarters;
makeChange.dimes = static_cast<int>(remainingMoney * 10);
float remainingMoney = money - makeChange.dimes;
makeChange.nickels = static_cast<int>(remainingMoney * 20);
float remainingMoney = money - makeChange.nickels;
makeChange.pennies = static_cast<int>(remainingMoney * 100);
return(makeChange);
}
return 0;
}
I know one of the problems is with remainingMoney that appears in lines 36-42
Another thing is I am getting an error that reads 'makeChange' : local function definitions are illegal
Any help with getting this program properly working is much appreciated.