Will someone please copy and run this program for me to confirm that this program runs in Xcode 3.2 on Mac OS 10.6.1? I'm having trouble in a class because, apparently, my teacher wasn't prepared for a student using the Xcode IDE... granted it may not be the most efficient design but give me a break, it's a programming fundamentals class heh.
Code:
#include <iostream>
#include <cmath>
using namespace std;
const int DOLLAR = 1;
const float QUARTER = .25;
const float DIME = .10;
const float NICKEL = .05;
const float PENNY = .01;
//Function prototypes
void itemizedChange(float, float, //Input
int&, int&, int&, int&); //Output
int main()
{
float total; //Input - Total ammount due
float cashTendered; //Input - Cash tendered
float changeDue; //Output - Change Due
int dollarReturn;
int quarterReturn;
int dimeReturn;
int nickelReturn;
int pennyReturn;
//Get total amount due.
cout << "Enter total amount due: $";
cin >> total;
while(total != 0)
{
//Get amount tendered.
cout << "Enter total cash tendered: $";
cin >> cashTendered;
cout << endl;
if (cashTendered > total)
{
//Display amount due and ammount tendered.
cout << "Amount due: $" << total << endl;
cout << "Amount tendered: $" << cashTendered << endl << endl;
//Display total change due.
changeDue = cashTendered - total;
cout << "Change due is: $" << changeDue << endl;
//Find exact amount of DOLLARS needed and subtract it from the change due.
dollarReturn = floor(changeDue);
cashTendered -= dollarReturn;
//Itemized change due and pass totals to main function
itemizedChange(total, cashTendered, //Input-Ammount due and cash tendered
quarterReturn, dimeReturn, nickelReturn, pennyReturn); //Output-Itemized change due
//Display an itemized list of change due.
cout << " " << dollarReturn << " dollars - " << quarterReturn << " quarters - "
<< dimeReturn << " dimes - " << nickelReturn << " nickels - " << pennyReturn << " pennies." << endl << endl;
}
else if(cashTendered < total)
{
//Display error message.
cout << "Amount Due: $" << total << endl;
cout << "Amount tendered: $" << cashTendered << endl << endl;
cout << "Cash tendered does not cover the total ammount due." << endl << endl;
}
else
{
//Display equal change message.
cout << "Amount Due: $" << total << endl;
cout << "Amount tendered: $" << cashTendered << endl << endl;
cout << "Cash tendered is equal to the total ammount, no change due." << endl << endl;
}
//Get total amount due.
cout << "Enter total amount due: $";
cin >> total;
}
//Display programmer ID
cout << endl;
cout << "KMorales M867L5p2.cpp" << endl;
cout << "Lab5 part2 11-19-09" << endl;
return 0;
}
//******************* Function Definitions *******************
//Calculate and display an itemized list of the change due
void itemizedChange(float total, float cashTendered, //Input-User defined input
int& quarterReturn, int& dimeReturn, //Output-Itemized change calculations
int& nickelReturn, int& pennyReturn) //Output-Itemized change calculations
{
float itemizedChangeDue;//Output - Holding place for total change due
float temp; //Output - Temporary holding place for value to be deducted from itemizedChangeDue
itemizedChangeDue = cashTendered - total + 0.0005;
//Find exact amount of QUARTERS needed and subtract it from the change due.
quarterReturn = itemizedChangeDue / QUARTER;
quarterReturn = floor(quarterReturn);
temp = quarterReturn * QUARTER;
itemizedChangeDue -= temp;
//Find exact amount of DIMES needed and subtract it from the change due.
dimeReturn = itemizedChangeDue / DIME;
dimeReturn = floor(dimeReturn);
temp = dimeReturn * DIME;
itemizedChangeDue -= temp;
//Find exact amount of NICKELS needed and subtract it from the change due.
nickelReturn = itemizedChangeDue / NICKEL;
nickelReturn = floor(nickelReturn);
temp = nickelReturn * NICKEL;
itemizedChangeDue -= temp;
//Find exact amount of PENNIES needed and subtract it from the change due.
pennyReturn = itemizedChangeDue/ PENNY;
pennyReturn = floor(pennyReturn);
temp = pennyReturn * PENNY;
itemizedChangeDue -= temp;
}