C++:Problem6

Problem:
Write a program that computes the cost of a long-distance call. The cost of the call is determined according to the following rate schedule:

a. Any call started between 8:00 A.M. and 6:00 P.M., Monday through Friday, is billed at a rate of $0.40 per minute.
b. Any call starting before 8:00 A.M. and after 6:00 P.M., Monday through Friday, is charged at a rate of $0.25 per minute.
c. Any call starting on a Saturday or Sunday is charged at a rate of $0.15 per minute.

The input will consist of the day of the week, the time started, and the length of the call in minutes. The out will be the cost of the call. The time is to be inputted can be in military time as 1300.

Software Design
A. Problem Write a program that computes the cost of a long-distance call. The cost of the call is determined according to the following rate schedule:

d. Any call started between 8:00 A.M. and 6:00 P.M., Monday through Friday, is billed at a rate of $0.40 per minute.
e. Any call starting before 8:00 A.M. and after 6:00 P.M., Monday through Friday, is charged at a rate of $0.25 per minute.
f. Any call starting on a Saturday or Sunday is charged at a rate of $0.15 per minute.

The input will consist of the day of the week, the time started, and the length of the call in minutes. The out will be the cost of the call. The time is to be inputted can be in military time as 1300.
B. Analyze
Given:
- Any call started between 8:00 A.M. and 6:00 P.M., Monday through Friday, is billed at a rate of $0.40 per minute.
- Any call starting before 8:00 A.M. and after 6:00 P.M., Monday through Friday, is charged at a rate of $0.25 per minute.
- Any call starting on a Saturday or Sunday is charged at a rate of $0.15 per minute.
C. Data Types:
1. Input variables
a) int Minutes;
b) int TimeStarted;
c) char choice;
d) string Day;

2. Output variables
a) double cost;
3. Program variable
a) double rate:

D. Formula:
a) cost = Minutes * rate;
E. Algorithm:
1. Introduction
a. Ask the user to input the starting time of the call in military time. (If the user input a wrong time, the program will ask the user again to input the starting time).
b. Ask the user to input the length of the call in minutes.
c. Ask the user to input the day of the week he/she made the call by inputting the first two letters of any day.
d. Ask the user if he/ she wants to calculate their bill again.
3. Calculations:
a) The total cost of the call and the rate per minute.

Display:
Enter the start time of the call in military time
For example, 1:30 = 1330: -34

You entered a non valid Time.
Enter the start time of the call in military time
For example, 1:30 = 1330: 5000

You entered a non valid Time.
Enter the start time of the call in military time
For example, 1:30 = 1330: 1200
Enter the length of the call in minutes: 200
Enter the day of the week on which you called using only the first two letters of the day. (Monday = mo): su

your rate for the call was $0.15 a minute
Your total cost: $30.00

Would you like to calculate your bill again? (y/n): y


Enter the start time of the call in military time
For example, 1:30 = 1330: 850
Enter the length of the call in minutes: 10
Enter the day of the week on which you called using only the first two letters of the day. (Monday = mo): mo

your rate for the call was $0.40 a minute
Your total cost: $4.00


Would you like to calculate your bill again? (y/n): y


Enter the start time of the call in military time
For example, 1:30 = 1330: 2000
Enter the length of the call in minutes: 10
Enter the day of the week on which you called using only the first two letters of the day. (Monday = mo): TH

your rate for the call was $0.25 a minute
Your total cost: $2.50


Would you like to calculate your bill again? (y/n): n



End of Program

Code:
#include
#include
#include
using namespace std;


int main ()
{

//Input variables
int Minutes, TimeStarted;
char choice;
string Day;

//Output variables
double cost, rate;

//Format demical place
cout << fixed << showpoint << setprecision (2);

//Using do while loop to ask the user if he/she wants to calculate his/her bill again
do
{
//Prompt the user to input
cout << "Enter the start time of the call in military time " << endl
<< "For example, 1:30 = 1330: ";
cin >> TimeStarted;
//Using while loop that ask the user to enter the starting time again if the user
//failed in inputting the starting time in the right format.
while(TimeStarted < 0 || TimeStarted >= 2400)
{
cout << "\nYou entered a non valid Time.";
cout << "\nEnter the start time of the call in military time " << endl
<< "For example, 1:30 = 1330: ";
cin >> TimeStarted;
}
cout << "Enter the length of the call in minutes: ";
cin >> Minutes;
cout << "Enter the day of the week on which you called using " <<
"only the first two letters of the day. (Monday = mo): ";
cin >> Day;
//Using if statment to determine the right cost of the call on a certain day.
if(Day == "mo"|| Day == "Mo" || Day == "MO" || Day == "tu" || Day == "Tu" || Day =="TU"
|| Day =="we" || Day == "We" || Day =="WE" || Day =="th" || Day == "Th" || Day =="TH"
|| Day == "fr" || Day =="Fr" || Day == "FR")
{
//Using if statment to determine the right cost of the call on a certain time.
if (TimeStarted >= 800 && TimeStarted <= 1800)
rate = 0.4;
else
rate = 0.25;
//Calculation
cost = Minutes * rate;
cout << "\nyour rate for the call was " << "$" << rate << " a minute"<< endl
<< "Your total cost: " << "$" << cost << endl;
}
else if(Day =="sa" || Day =="Sa" || Day =="SA" || Day =="su" || Day =="Su" || Day =="SU")
{
rate = 0.15;
//Calculation
cost = Minutes * rate;
cout << "\nyour rate for the call was " << "$" << rate << " a minute"<< endl
<< "Your total cost: " << "$" << cost;
}
else
cout <<"You entered a non valid entry. Try again.";

cout << endl << "\nWould you like to calculate your bill again? (y/n): ";
cin >> choice;
cout << endl << endl;

}
while( choice =='Y' || choice == 'y');

//closing
cout << "\nEnd of Program\n\n";
return 0;
}