// This program does so and so ... // Author: .... Date: ... // ... // Metrowerks CodeWarrior version #include using namespace std; // declare global constants const int UNITS_PER_ROOM = 15; const int FIXED_UNIT_COST = 5; const int ADD_UNIT_COST = 2; int main() { // declare input variables int nosRooms; int oldMeterReading; int newMeterReading; char replyYorN; int totalCostPence; int totalCostPound; int remainderPence; // Input Initial Data cout << "What is the number of rooms in your house? "; cin >> nosRooms; cout << endl; cout << "What is the OLD Meter reading? "; cin >> oldMeterReading; cout << endl; cout << "What is the NEW Meter reading? "; cin >> newMeterReading; cout << endl; // Perform Calculations 1 // Calculate Number of Units for Fixed Charge int fixedUnits = UNITS_PER_ROOM * nosRooms; // Calculate Fixed Charge in Pence int fixedCost = fixedUnits * FIXED_UNIT_COST; // Calculate Actual Number of Units int actualUnits = newMeterReading - oldMeterReading; // Is Actual Number than Fixed Charge Number? if (actualUnits > fixedUnits) { // TRUE Case // Calculate Additional Number of Units int aboveUnits = actualUnits - fixedUnits; // Calculate Total as Fixed Charge plus Additional Charge totalCostPence = fixedCost + aboveUnits * ADD_UNIT_COST; } else { // FALSE Case // Make Total equal to Fixed Charge totalCostPence = fixedCost; } // Is result in pounds and pence needed ? cout << "Do you want cost in pounds and pence (answer Y or N)? "; cin >> replyYorN; cout << endl; if (replyYorN == 'Y') { // Case Yes // Perform Calculations 2 // Find Number of Pounds in Total totalCostPound = totalCostPence / 100; // Find Remainder in Pence in Total remainderPence = totalCostPence % 100; // Output Total in Pounds and Pence cout << "Total Due: " << totalCostPound << " pounds and " << remainderPence << " pence." << endl; } else if (replyYorN == 'N') { // Case No // Output the Total Cost in pence cout << "Total Due: " << totalCostPence << " pence." << endl; } else { // Case neither Yes nor No - report Erroneous input cout << "Error in reply!" << endl; } cout << "the end of program" << endl; return 0; }