Imput file to output file

Im having trouble with figuring this out. Will someone please help me.


Problem: Write a program that computes the cost of a long-distance call. The cost of the call is determined according to the following rate schedule:

a. Any call started between 7:00 A.M. and 9:00 P.M., Monday through Friday, is billed at a rate of $0.30 per minute.
b. Any call started before 7:00 A.M. or after 9:00 P.M., Monday through Friday, is billed at a rate of $0.15 per minute.
c. Any call started on a Saturday or Sunday is billed at a rate of $0.10 per minute.

The input will consist of the day of the week, the time the call started, and the length of the call in minutes. The output will be the cost of the call. Input will come from the input file “Project_3_input.txt” and go to “Project_3_output.txt”, which you will create.

The day of the week will be read as one of the following pairs of character values, which are stored in two variables of type char: Mo Tu We Th Fr Sa Su

The time is to be input in military-time notation, hours followed by minutes, so the time 1:30 P.M. is input as: 13 30

Be sure to allow for both uppercase and lowercase letters or a combination of the two. You MUST accept both letters, and check both letters for validity. (Think: otherwise the program would accept “Sq” if you are only checking for weekend days by looking for “S”). If an incorrect day of the week is entered, skip the part of the code that will read in start time and call length.

The number of minutes will be input as a value of type int. (You can assume that the call time is rounded up to a whole number of minutes.) Your program should include a loop that accepts call data until the end of the file is reached.


this is my input file which i have as Project_3_input.txt
//*************************
Mo 17 30 15
Sa 9 00 30
Tu 3 30 45
Sq
Fr 21 01 60
//**************************


This is my code i have already (Instead of putting it in the output file right now i have it outputted to the screen.)

//***********************************************************************

#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

const double mid_day = 0.3;
const double night = 0.15;
const double weekend = 0.1;

int main ()
{

ifstream import;
ofstream output;
import.open("Project_3_input.txt");
output.open("Project_3_output.txt");

char day;
int num_day;
int time;
int length;
double cost;




if (import.fail()) {
cout<<"Error opening file"<<endl;
} else {

import >> day;
import >> time;
import >> length;
while(!import.eof())
{



if((day=='Mo')||(day=='mo'))
{
num_day = 1;
}else if((day=='Tu')||(day=='tu'))
{
num_day = 2;
}else if((day=='We')||(day=='we'))
{
num_day = 3;
}else if((day=='Th')||(day=='th'))
{
num_day = 4;
}else if((day=='Fr')||(day=='fr'))
{
num_day = 5;
}else if((day=='Sa')||(day=='sa'))
{
num_day = 6;
}else if((day=='Su')||(day=='su'))
{
num_day = 7;
}else{
import.ignore();
}

if(((time>700)&&(time<2100))&&(num_day<=5))
{
cost = length*mid_day;
}else if((time<700)||(time>2100)&&(num_day<=5))
{
cost = length * night;
}else{
cost = length * weekend;
}


cout<< cost;


}
}
import.close();
output.close();

return 0;
}
//**************************************************************************


I would greatly appreciate it if someone could even give me advice on where to go from here. This program displays numbers and runs constantly until hitting the red "X".
Single quotes ' ' like this mean what's inside these is a character, not string... so this program shouldn't even run. Furthermore, comparing cstrings ("this is a cstring") doesn't work with the == operator, you would either have to use strcmp from the cstring header, or compare them with string::compare (string("cstring1").compare("cstring2")). Your "day" variable is also declared as a char, which means it's just a single character. You should use char* or string instead.
Last edited on
Topic archived. No new replies allowed.