This is the code I have for woring out a phonebill, it isn't outputting the correct results however and I'm not sure what to do next.
The program involves computing the cost of a long distance call. The cost being dependent on the time of day and the day of the week. The data file uses the header card technique and after the program reads in the header card value, it should use a loop to read in and process that number of phone call records. The program should also calculate and report a total.
prog6dta.txt
6
M 13:30 5
M 22:15 6
T 7:30 8
R 8:45 10
S 13:30 5
U 22:15 6
Code:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
using namespace std;
int main()
{
ifstream in_stream;
int count=1;
int i=0;
char day;
int hour=0, min=0, totalTime=0;
char col;
double cost=0.0, total=0.0;
double rate=0.0;
in_stream.open("A:\\prog6dta.txt");
in_stream >> count;
cout << "Call" << setw(10) << "Cost" << endl;
if (count > 0)
{
in_stream >> day >> hour >> col >> min >> totalTime;
for(i=0; i<count; i++)
{
switch (day)
{
case 'M':
case 'T':
case 'W':
case 'R':
case 'F':
if(hour>=8 && hour <=17)
rate = 0.4;
else
rate = 0.25;
default:
rate = 0.15;
}
if (totalTime > 0)
total = rate * totalTime;
else
total = 0.0;
cost+= total;
cout << fixed << showpoint << setprecision(2);
cout << setw(4) << i++ << setw(9) << total << endl;
in_stream >> day >> hour >> col >> min >> totalTime;
}
}
else;
cout << "total= " << setw(7) << cost << endl;
in_stream.close();
return 0;
}
Sample Output
*/
Call Cost
1 2.00
2 1.50
3 2.00
4 4.00
5 0.75
6 0.90
Total= 11.15
*/