I creating a program that can output the title, artist, and price of songs inside a orders.txt
file.
I'm having a hard time assigning variables to the contents and outputting them to the console successfully.
An example of the order list is:
Undead
Hollywood Undead
4.50
Paradise Lost
Hollywood Undead
3.00
Hello
Adele
5.00
Out Of Control
Hoobastank
6.00
I'm currently using a while loop to output all the contents. I know I need to use getline for separate variables for title and artist. I also know need to make the price int.
Unfortunately, when I debug the code, the loop doesn't end or the formatting is off. I'm using iomanip with setw()
.
PLEASE HELP! I've tried making price a string and then converting it into an int.
Here is my source code:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
ifstream inputFile;
inputFile.open("Orders.txt");
int number, price, totalNum = 0;
double total;
string title, artist;
cout << left << setw(36) << "Title";
cout << setw(22) << "Artist" << left << "Price" << endl;
while (!inputFile.eof())
{
getline(inputFile, title);
getline(inputFile, artist);
inputFile >> price;
cout << left << setw(36) << title;
cout << setw(22) << artist << left << "$" << price << endl;
}
inputFile.close();
system("pause");
return 0;
}