Student Needing Help (not cheating-just help)

This is a discussion on Student Needing Help (not cheating-just help) within the C++ Programming forums, part of the General Programming Boards category; I have to do an assignment for my C++ class which I have to make a program that: -Opens a ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    9

    Student Needing Help (not cheating-just help)

    I have to do an assignment for my C++ class which I have to make a program that:

    -Opens a .txt or .dat file with the following information- day a phone call started, time the call started, how long the call lasted (in minutes)
    -Then reads the .txt or .dat file in and process it by reading in the day of the week.
    -If it is a M-F from 8am-6pm, calc. $.40 per min
    -If it is a M-F from 6pm-8am, calc. $.25 per min
    -If it is a S-S, calc. $.15 per min
    -Then it has to out put the call information to an output file, along with the cost for each call, and the total cost of all calls.

    The assignment says that the input file only need to contain 5 calls.

    I'm having a lot of trouble with this assignment and was wondering if someone could please help me out.

    I'll post what I have so far, I'll attach the .cpp file.

    What I have so far is just a bare-bones outline of what I want to do.
    I keep getting an error (illegal else without matching
    if).

    So if anyone can/will help me out, please do.

    Thanks.

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    9
    here's the .cpp file
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    9
    In my when I bring in the 'next char', which is a digit, say like the '6' outof '64' how can combine the two (the 6 & the 4) so they make 64 again. Is there a way, or should I use a int/double for next instead of the char, and if I do, how do I tell it to take all the numbers, like the 6 & the 4, and stop at the next space?

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Check out the atoi() function which converts a string to an integer. However, you might not need to do that.

    The method you use to read input from a file can be tailored based on how the input file is organized. In your case, the input file might look something like this:

    M 8:00pm 30
    T 7:00am 12
    W 6:12am 52

    You can't read all the data into a numerical type because there are characters in the input. You can use a string type, but then you have the problem of trying to perform calculations on non-numerical types. You can use atoi() to solve that problem, but there is an easier way: read input into more than one variable. You could declare three variables like this:

    char day = 0;
    string time;
    int minutes = 0;

    and then read in data into each of those variables:
    Code:
    while(!infile.eof())
    {
    	infile>>day;
    	infile>>time;
    	infile>>minutes;
    
    	//perform calculations and output
    	//the variables and the calculations
    }
    "how do I tell it to take all the numbers, like the 6 & the 4, and stop at the next space?"

    The >> operator is defined so that it skips any whitespace preceeding the input, and it will stop reading when it encounters a space. So your input file can look like this and it won't make a difference:
    Code:
        M   8:00pm   30
    T   7:00am                        12
         W                6:12am 52
    Last edited by 7stud; 04-09-2003 at 04:07 AM.

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    9
    thanks for the reply...

    i'll play around with it again tomorrow (i got school/work tonight)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Updating in a sequential file?
    By Ronnyv1 in forum C Programming
    Replies: 1
    Last Post: 03-24-2009, 05:41 PM
  2. Database assignment is Killing me!
    By Boltrig in forum C Programming
    Replies: 2
    Last Post: 11-29-2007, 03:56 AM
  3. Student desperately needing help!
    By pinkpanther1586 in forum C Programming
    Replies: 4
    Last Post: 10-26-2003, 08:46 AM
  4. LinkList Sorting in C
    By simly01 in forum C Programming
    Replies: 3
    Last Post: 11-25-2002, 01:21 PM
  5. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 09:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21