// PROGRAM: dcheung_hours.cpp // PROGRAMMER: David Cheung // DATE: 10/09/06 // PURPOSE: Calculate usage charges for certain hours of the day. // INPUT: Time of day in hour (24 hr clock) // Usage charge // OUTPUT: Function of the program // Instructions on how to exit the program // Proper prompts for each input // Normal or discounted charge with proper description // DESCRIPTION: /* Algorithm: Input the time of day in hour based on a 24hr clock While time of day is > 0 Input the usage charge per hour If time of day is less than 8 or greater than 17 Actual usage equals 20% of usage Display discounted charge Else Actual usage equals usage Display peak hours - no discount Input the next time of day in hour based on 24hr clock End while loop */ #include #include using namespace std; int main() { int varHour; // Time of day float varStdUsage, varActualUsage; // Usage charges // Use a fixed number notation and show the decimal point cout << fixed << showpoint; // Start the program cout << "Cost Adjuster" << endl << endl; cout << "Enter a negative time to quit" << endl << endl; cout << "Hour -> "; // Initial Time of day goes here cin >> varHour; while (varHour >= 0) // As soon as varHour goes negative, break the loop { cout << setprecision(2) << "Charge -> "; // Regular charge goes here cin >> varStdUsage; if (varHour < 8 || varHour > 17) // Off-peak discount { varActualUsage = varStdUsage * 0.8; // Calculate the discount cout << "Normal Charge -> " << varStdUsage << endl; cout << "Discounted Charge -> $" << varActualUsage << endl; } else // Peak hours? no discount for you! { varActualUsage = varStdUsage; cout << "Normal Charge -> " << varActualUsage << endl; cout << "Peak Hours - no discount" << endl; } cout << endl; cout << "Next hour -> "; // Start over unless hour is negative cin >> varHour; } cout << endl << "Bye!"; // system("pause"); // This is a DOS-specific command return 0; }