Please help fast!

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.
***********************************************************************
Input:
Mo 17 30 15
Sa 9 00 30
Tu 3 30 45
Sq
Fr 2101 60
**********************************************************************
This is what i have so far. can't seem to get it right using visual studio

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

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

int main ()
{
ifstream infile;
ofstream outfile;
infile.open("Project_3_input.txt");
outfile.open("Project_3_output.txt");

char day[3];
int num_day;
int time;
int length;
double cost;

infile >> day >> time >> length;


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 if (infile.fail()) 
{cout<<"Error opening file" <<endl;}
else
{infile.ignore();}

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

cout<< cost;

infile.close();
outfile.close();

return 0;
}
Last edited on
If there can you please use when submitting please
Makes it much easier to read :) it's just on the right ->

Also what are you actually have problems with?
Last edited on
Everytime i run the program it says error opening file and then gives me some wierd negative number. i believe i have saved the input file correctly correctly.
make day a std::string.
then that won't let me use the == or the ||
On the contrary. It'll let you use them in a way that'll actually do what you're expecting it to, because what it does now probably isn't what you're expecting. :|

-Albatross
Last edited on
so to declare day i should put std::string day[3]? because it says no operator matches the ==
Last edited on
Just omit the [3]. :)

EDIT: Oh, and for proper coding purposes, add #include <string> at the top of your file if you haven't already.

-Albatross
Last edited on
well that just fixed all the scary red squigglies. thanks

but now my output is this:
Error opening file
-1.28849e+008Press any key to continue . . .
Last edited on
Well, I don't know what time zone you're in, so... sorry. However, if you changed char to string, axed the [3], and #included <string>, then your program should compile perfectly.

-Albatross
it compiles perfect thanks to you. i'm just not getting the right output. and i'm in eastern, its 830. i'll have to pick it apart and try to find my error. thanks again
i feel so stupid. when i said i saved it correctly, i lied. it wasn't in the same file as the program.
Dumb question but i get the output only for the first line of the input file. How do you have it read the rest of the file?
i'm assuming you copied my code which i don't care, so i'm having the same problem too. hopefully a professional we'll see we're in distress and help
I didnt copy the code ive been sitting on it for two days now trying to find a forum that would have the specific part i was looking for
Topic archived. No new replies allowed.