Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Back in the days of \"long distance,\" phone calls beyond your local community w

ID: 3670639 • Letter: B

Question

Back in the days of "long distance," phone calls beyond your local community were billed by the minute, with different rates depending on day of the week and the time of the day that the call was made. (The phone lines were less in use on weekends and at night, when businesses were not using them as extensively.) This program computes a person's phone bill based on this type of calling. Write a C program that computes the cost of a long-distance call, total cost of all the calls made and cost of the most expensive call. The cost of the call is determined according to the following rate schedule: Any call started between 8:00 a.m. (800 hours) and 6:00 p.m. (1800 hours) during the weekdays is billed at the rate of $0.20 per minute. Any call started after 6:00 p.m. (1800 hours) until 11:00 p.m. (2300 hours) during the weekdays is billed at the rate of $ 0.15 per minute. Any call made during the weekend (Saturday and Sunday) and after 11:00 p.m. and before 8:00 a.m. every day is billed at the rate of $0.10 per minute. The input will consist of the day ('d' for weekday or 'e' for weekend), the time call started, and the length of the call in minutes. The time is to be input in 24-hour notation. The day of the week will be read as a char. The time and the length will be integer values. You do not have to worry about a call going from one rate to another. For example if the call started at 745 and the length of the call is 30 minutes, your entire call will be calculated at the rate of the time call started. Use #define to declare the rates as constants. Use loops and if statements in the main of your program You are not required to use functions, but you can if you want. Remember to initialize the sum and the most expensive call to appropriate values.

Explanation / Answer

#include <stdio.h>
#include<stdlib.h>
#define weekday86 0.20
#define weekday611 0.15
#define weekend 0.10
#define weekday11 0.10
int main()
{
int sum=0;
int expensivecall=0;
char arr1[20]="Weekday";
char arr2[20]="Weekend";
int times;
int lengthcall;
char choice;
char day;
char inputday[20];
int cost=0;
int totalcost=0;
do
{
printf("Enter Day Weekday or Weekend ");
scanf("%s",&day);
printf(" Enter the time of call started");
scanf("%d",&times);
printf(" Enter the length of call ");
scanf("%d",&lengthcall);
if(day=='w')
{
inputday[20]=arr1[20];
if(times>=800 &&times<1800)
{
cost=lengthcall*weekday86;
}
else if(times>=1800 && times<2300)
{
cost=lengthcall*weekday611;   
}
else
cost=lengthcall*weekday11;
  
}
else
{
inputday[20]==arr2[20];
cost=lengthcall*weekend;
}
printf(" %s %d minute call started at %d hrs will cost %d ",inputday,lengthcall,times,cost);
printf("DO you have another ? (Y or N)");
scanf("%s",&choice);
totalcost=totalcost+cost;
}while(choice=='Y');
printf("Total Cost %d",totalcost);
return 0;
}