#include <iostream> #include <string> #include <iomanip> using namespace std; int main() { string day; int startTime, minutes; double cost, rate; char ch ; cout << fixed << showpoint << setprecision(2); do { cout << "Enter start time of the call(For example, 2:30 = 2330): " << endl; cin >> startTime; while (startTime<0 || startTime>2400) { cout << "\nInvalid time."; // keep asking for time input until it is valid cout << "Enter start time of the call(For example, 2:30 = 2330): "; cin >> startTime; } cout << "Enter length of the call in minutes: "; cin >> minutes; cout << "Enter the day of the week: "; cin >> day; if (day == "monday" || day == "MONDAY" || day == "tuesday" || day == "TUESDAY" || day == "wednesday" || day == "WEDNESDAY" || day == "THURSDAY" || day == "thursday" || day == "friday" || day == "FRIDAY") { if (startTime >= 800 && startTime <= 1800) rate = 0.4; else rate = 0.25; cost = minutes * rate; cout << "\nRate for the call was " << "$" << rate << " a minute" << endl << "Your total cost: " << "$" << cost << endl; } else if (day == "saturday" || day == "SATURDAY" || day == "sunday" || day == "SUNDAY") { rate = 0.15; cost = minutes * rate; cout << "\Rate for the call was " << "$" << rate << " a minute" << endl << "Your total cost: " << "$" << cost; } else cout << "\nInvalid."; cout << "\nWould you like to calculate your bill again ? (y / n) : "; cin >> ch; cout << endl; } while (ch == 'Y' || ch == 'y'); cout << "End of programm" <<endl; return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter