Question: My C + + code is not printing the 'Night call is free' value where applicable in the Minutes used so far column, it isn't
My C code is not printing the 'Night call is free' value where applicable in the Minutes used so far column, it isn't printing the correct values for the Cost column, and the Total cost of the bill is only displaying the basic monthly rate of $ The code is below and a screenshot of the requirements is attached in the image.
#include
#include
#include
using namespace std;
Constants
const double DAYTIMERATEWITHINAREA ;
const double DAYTIMERATELONGDISTANCE ;
const double BASICMONTHLYRATE ;
const int NIGHTSTARTHOUR ; pm
const int NIGHTENDHOUR ; am
const int FREEMINUTESDAYTIME ;
Structure to hold call information
struct Call
int startHour;
int duration;
char type;
;
Function to calculate the cost of a call
double calculateCallCostCall call
double cost ;
if callstartHour NIGHTSTARTHOUR && call.startHour callstartHour && call.startHour NIGHTENDHOUR
Night time call
return cost; Night calls are free
else
Daytime call
int additionalMinutes max call.duration FREEMINUTESDAYTIME;
if additionalMinutes
if calltype A
cost additionalMinutes DAYTIMERATEWITHINAREA;
else if calltype L
cost additionalMinutes DAYTIMERATELONGDISTANCE;
return cost;
int main
ifstream inFilephonecalls.txt;
if inFile
cerr "Unable to open file";
return ;
double totalBill BASICMONTHLYRATE;
int totalDaytimeMinutes ;
Call call;
Print header
cout "Cellphone charges MP by omitted my nameSkills needed: logical expressions, nested ifelse statements
Problem:
the day or the night.
daytime call.
information about each call on a separate line.
This information is:
The time of day that the call started using an int to represent a hour clock
The duration of the call in minutes int and
A char for the type of call A for a call within the area, for a longdistance call.
For example, the line
A
means that the call started at : lasted for minutes and was within the calling area.
SUGGESTION
You should design, compile, run and debug your program in stages.
You might start by testing if your program can just read and echo the data file.
After this is working accurately, write the code to determine whether the call is a day or night one.
Make sure you always submitupload the cpp files and the output files or a screen shot of the output.
Sample output from the first few lines of the data follows:
Cellphone charges MP by your name goes here
Time Duration Type of call Minutes used so far Cost" endl;
cout setw "Time" setw "Duration" setw "Type of call" setw "Minutes used so far" setw "Cost" endl;
Read call data and calculate costs
while inFile call.startHour call.duration call.type
cout setw call.startHour setw call.duration setw call.type;
Update totalDaytimeMinutes for daytime calls only
if callstartHour NIGHTSTARTHOUR && call.startHour callstartHour && call.startHour NIGHTENDHOUR
if callstartHour call.duration NIGHTENDHOUR && callstartHour call.duration NIGHTSTARTHOUR
cout setw "Night call is free";
else
totalDaytimeMinutes call.duration;
cout setw totalDaytimeMinutes;
else
totalDaytimeMinutes mincallduration, FREEMINUTESDAYTIME;
cout setw totalDaytimeMinutes;
double callCost calculateCallCostcall;
totalBill callCost;
if callCost
cout setw fixed setprecision callCost endl;
else
cout setw$ endl;
Print total bill
cout "Total bill for the month: $ fixed setprecision totalBill endl;
inFile.close;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
