[OT] C++ programming help
Results 1 to 3 of 3
  1. #1
    Tech Wizard
    Join Date
    Apr 2011
    Posts
    23

    Default [OT] C++ programming help

    This is very off topic but I was hoping some people here will know more than I do about this.

    I need to hand in a c++ program by midnight and im just missing one thing....

    The program has to be able to read a data from another file "books.dat" and output the number of orders and the total, subtotal, tax,discount and shipping for each order. I was able to output 4 of the order "templates" but it seems like it wont read the data.

    Example of "books.dat":

    5 S
    2.9912.45 13.23 21.99 24.59
    1 E
    34.95
    3 5
    8.99 12.45 7.58

    The first number in the first line is the number of books
    the letter in the first line is the shipping method
    the third set is the price for the number of books

    ex:
    (# of books) (shipping method)
    (price of book)(price of book)

    I need to read the first line as two different variables and the second line as a separate variable

    What I have is

    fp>> books >> shipping;

    for(int i=1; i<= books; i++)
    {
    fp>>prices;
    sum+=prices;
    }


    I was hoping someone can help me out. Really appreciate it.
    Just a broke college student trying to pay my way through college by Djing

    Setup: HP G62 3GB Dual-Core 2.3GHz; Traktor Pro 2; Numark Mixtrack; Creative Soundcard.

  2. #2
    Schreiberie Meister Afterhour Ali's Avatar
    Join Date
    Jun 2008
    Location
    Tekki's crotch
    Posts
    1,598

    Default

    Hello DjSpekz,

    Did you find out what didn't work?

    I didn't really understand this sentence:

    I was able to output 4 of the order "templates" but it seems like it wont read the data.
    You usually get the fastest help with programming-tasks like this at StackOverflow.
    DJDiscourse.com — the new DJ community

  3. #3
    Tech Guru kiss-o-matic's Avatar
    Join Date
    Aug 2009
    Location
    Tokyo
    Posts
    505

    Default

    What are you using to read the lines? you should copy & paste your code.... no way we can tell what's wrong w/ just what's there.

    You can use C's getline(), and then you'll need to read each line, and store the value every time you encounter a whitespace. You'll also need to know what line you're on to know exactly what the data is.

    EDIT:
    Okay, I under stand the data.
    In your loop, you'll need to have an int stored for # of orders, a char or string for the type of order, and probably a vector (or array) for the prices. Read the first line, get the number of items (cast it to int, w/ atoi()). Read the next line... store each value to double. Rinse, repeat.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •