123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
#include <iostream> using namespace std; const float maxPerUnit = 20000.00; //minPerChild includes a standard fift consisting //of a bath towel and facecloth const float minPerChild = 100.00; const float maxPerChild = 180.00; //depending on the amount, the child may also get //one or more of the following: const float TOOTHBRUSH = 29.95; const float HIGHLIGHTERS = 25.95; const float CRAYONS = 17.95; const float NOTEBOOK = 12.95; const float PEN = 9.99; //calculate amount allowed per child float calcAllowedPerChild(int nrChildernP) { float AmountPerChild; AmountPerChild = maxPerUnit / nrChildernP; if (AmountPerChild > 180) AmountPerChild = 180; else if (AmountPerChild < 100) AmountPerChild = 100; return AmountPerChild; } //calculate the actual spent on an ophanage float calcActualAmount(float amtGift, int nrChildern) { float amtToothbrush = 0.0, amtNotebook = 0.0, amtHighlighters = 0.0, amtCrayons = 0.0, amtPen = 0.0; float total, totalForAll; total = amtGift; total -= TOOTHBRUSH; if (amtGift > 100) { total = amtGift - minPerChild; while (total > PEN) { if (total > TOOTHBRUSH) { total -= TOOTHBRUSH; amtHighlighters += total; } else if (total > HIGHLIGHTERS) { total -= HIGHLIGHTERS; amtHighlighters += total; } else if (total > CRAYONS) { total -= CRAYONS; amtCrayons += total; } else if (total > NOTEBOOK) { total -= NOTEBOOK; amtNotebook += total; } else { total -= PEN; amtPen += total; } } } totalForAll = amtToothbrush + amtNotebook + amtHighlighters + amtCrayons + amtCrayons + minPerChild; return totalForAll; } float calcTotalSpent(int nrChildern, float amtSpentPerChild) { return nrChildern * amtSpentPerChild; } int main( ) { float amtGift;//Allowed amount per child float amtSpentPerChild = 0.00;//Actual Amount per child float totalSpent = 0.00;//total spent for one ophenage float totalAll = 0.00;//total spent for all ophenages int nrChildren; //number of children per ophenage for (int i = 1; i <= 4; i++) { cout << "Orphanage " << i << endl; cout << "Enter the number of children: "; cin >> nrChildren; amtGift = calcAllowedPerChild(nrChildren); cout.setf(ios::fixed); cout.precision(2); cout << endl << "Allowable amount per child: R" << amtGift; cout << endl << endl; amtSpentPerChild = calcActualAmount(amtGift, nrChildren); cout << endl << "Actual amount spent per child: R" ; cout << amtSpentPerChild << endl << endl; totalSpent = calcTotalSpent(nrChildren, amtSpentPerChild); cout << endl << "The actual amount spent was: R" ; cout << totalSpent << endl; cout <<endl; } //calculate the of the money spent on all orphanages totalAll= totalAll + totalSpent; cout << endl; } //display the total spent on all ophanages cout <<"The total spent on All the ophanages is: R"; cout << totalAll <<endl; return 0; }
totalAll= totalAll + totalSpent;