Answer to Question #306642 in C++ for sanza

Question #306642

write a program to calculate the cost of long distance call

• Any call made between 8:00 AM and 6:00 PM, Monday through Friday, is billed at rate of 6 rupees per min.

• Any call made before 8:00 AM or after 6:00 PM, Monday through Friday, is charged at rate of 3.75 rupees per min

• Any call made on a Saturday or Sunday is charged at a rate of 1.5 rupees per min.



The program will input the day of the week along with other inputs. The day of the week will be read as one of the following pairs of characters, which are stored in two variables char:

Mo,Tu,We,Th,Fr,Sa,Su.


If call is started on Friday at 11:55 PM and ends at 12:05 AM on Saturday then rate of call be calculated as cost of call as per schedule on Friday for first 5 min plus the cost of call as per schedule on Saturday for rest of the 5 min. Similarly, if call starts on Sunday at 11:55 PM and ends at 12:05 AM on next day i.e. Monday, then cost of the call be calculated as charges as per schedule on Sunday plus charges as per schedule on Monday.


1
Expert's answer
2022-03-06T18:18:46-0500
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
int main ()
{
	int minutes, startTime;
	char ch;
	string Day; 
	double cost, rate;
	cout << fixed << showpoint << setprecision (2); 
	do
	{
		cout << "Enter start time of the call(For 
example, 2:30 = 2330): ";
		cin >> startTime;
		while(startTime < 0 || startTime >= 2400)
		{
			cout << "\nInvalid time.";
			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 << endl << "\nWould you like to calculate your bill again? (y/n): ";
		cin >> ch;
		cout << endl << endl;

	}
	while( ch =='Y' || ch == 'y');
	cout << "\nEnd of Program\n\n"; 
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog