instructions

Skills needed: while loop, logical expressions, nested if-else statements

Your assignment for MP3 is to calculate the monthly bill for a cell phone user given the following rate structure. Note that this is a simpler structure than in real life – you do NOT have to be concerned about whether it is a weekday or a weekend, just whether the call is made during the day or the night.

1.	All evening and night calls that begin from 6pm (exactly) up to and including 5:59am are free and there is no limit on these minutes used. As long as the call starts before 6am (even if it lasts until after 6am) it is counted as a night time call.
2.	The basic monthly rate is $39.99 which includes the first 200 minutes of daytime calls (from 6am up to and including 5:59pm).  These can be within the calling area or long distance. If a call begins before 6pm and lasts until after 6pm, the entire call is treated as a daytime call.
3.	As soon as the 200 minutes have been used, there is a charge for daytime calls at the rate of $0.29 per minute if the call is within the area, or $0.69 per minute for long distance. For the one call that begins before the 200 minutes have been used but lasts until over the 200 minutes, only the portion over the 200 minutes is charged.  All subsequent daytime calls are charged for the entire duration of the call.  Again, if a call begins in the daytime period and is subject to charge, the entire duration is chargeable (as above).

the infile

1100 30 L
2230 20 A
1200 100 A
559 40 L
1530 60 L
800 15 A
1800 20 L
600 10 A
1730 10 L
1759 5 A
1 3 A

what i have come up with so far.

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
	int Time;
	int Duration;
	char TofCall;
	string MinutesUsed;
	double Cost;
	
	// declare the stream names
	ifstream infile;
	ofstream outfile;

	// declare the stream files
	infile.open("indata.txt");
	outfile.open("outdata.txt");

	
	// get the input
	outfile << "Time " << " Duration " << " Type of call " << " Minutes used so far " << " Cost " << endl;
	outfile << ' ' << endl;		//blank line 

	while (infile) 
	{

	infile >> Time;
	infile >> Duration;
	infile >> TofCall;

		if(Time <= 0600 || Time >= 1800)
			MinutesUsed = "night time";
		else if(Duration >= 0)
			

		

		

	//output
	outfile << left << setfill('.') << setw(4) << Time;
	outfile << right << setfill('.') << setw(8) << Duration;
	outfile << right << '.' << setw(10) << TofCall;
	outfile << right << '.' << setw(20) << MinutesUsed << endl;

	}

	
	return 0;
}

my output:

Time Duration Type of call Minutes used so far Cost

1100......30..........L....................
2230......20..........A...........night time
1200.....100..........A....................
559.......40..........L....................
1530......60..........L....................
800.......15..........A....................
1800......20..........L...........night time
600.......10..........A....................
1730......10..........L....................
1759.......5..........A....................
1..........3..........A...........night time
1..........3..........A...........night time

what the output is supose to look like

Sample output from the first few lines of the data file follows:

Cellphone charges - MP3 by (your name goes here)

Time Duration Type of call Minutes used so far Cost

1100 30 L 30 $0.00
2230 20 A Night call is free
1200 100 A 130 $0.00
0559 40 L Night call is free
1530 60 L 190 $0.00
0800 15 A 205 $1.45

THANKS FOR YOUR HELP _*Jenna*_

Comments
Thanks for taking the time to read the Rules and learn how to use code tags correctly :)

You are going to have to keep at least one running tally: the number of daytime minutes. You should initialize this to 0 before your while loop starts. When you decide that a call is a daytime call, you'll increment this variable (let's call it numDaytimeMinutes) by the number of minutes the call lasts. If and when the 200 minute mark is hit, you could also have a boolean flag called "startCharging". Initialize it to false outside of the loop and set it to true when the 200 minute mark is hit.

This article has been dead for over six months. Start a new discussion instead.