Been running at this problem all day, have a programming assignment due tomorrow night. The program asks for you to read data from a text file of orders of album, artist, and pricing display it and then get the total of cost and then print it into a summary txt file. I have the first line, badly formated, but it prints. When I try to implement anyway to get the second it gives me just the album title and then what I am guessing is the price in scientific notation. Here is my code as of now:
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
Right now it just displays the first line and then second album name with scientific notation number:
You have submitted the following order:
**********************************************************************
Title Artist Cost
Turn on the Bright Lights Interpol 9.49
House of Jealous Lovers -9.25596e+61
House of Jealous Lovers -9.25596e+61
House of Jealous Lovers -9.25596e+61
House of Jealous Lovers -9.25596e+61
Total -3.70239e+62
I'm just looking to get to the next line. Any help would be great.
Turn on the Bright Lights
Interpol
9.49
House of Jealous Lovers
The Rapture
1.29
Fever to Tell
Yeah Yeah Yeahs
6.99
Desperate Youth, Blood Thirsty Babes
TV on the Radio
8.91
The Fragile
Nine Inch Nails
12.49
Took me a minute to realize they were names of songs/albums.
Anyway, for yourself, look into how to use a while loop or a for loop, it will save you a lot of typing.
Loops and checking for file.good() will make it so you can deal with any size of file without knowing it's size before hand.
Your problem is that the fileInput >> variable; doesn't seem to go to the next line so your next getline is called on the same line as the price of the previous album. This throws off the rest of your blocks because it's then trying to read author information into a double which is not going to work.
Try inputFile.ignore(); at the top of each of your following album info blocks.
Thanks for responding I'm just eating dinner now and going to try your suggestion. The ofstream seems like I can get that fine it was just this because of the outputs I was getting. I'll respond with my results.
Glad to help, but in the future you might get quicker answers in the beginner's forums. (More eyes over there.)
After you post, you could also hit edit and wrap your code in code brackets (its the <> symbol in the format buttons). For some reason on this site they don't always work when writing a main post but work fine when editing or replying. Just highlight the code and hit that button.