[OT] C++ programming help

[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.

Hello DjSpekz,

Did you find out what didn’t work?

I didn’t really understand this sentence:

You usually get the fastest help with programming-tasks like this at StackOverflow.

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.