Hi,
My assignment is to figure out the total time for a group of songs and see how they will fit on a CD. The data are on file songs.dat and looks like this:
300
250
500
570
380
425
275
305
320
450
The time is entered as seconds. After all the data has been read, the application should print a message indicating the time remaining on the CD. The out put should be in the form of a table with colums and headings written on a file.
The chart should look like this:
Song Song Time Total Time
Number Min Sec Min Sec
1 5 10 5 10
2 7 42 12 52
5 4 19 17 11
3 4 33 21 44
4 10 27 32 11
6 8 55 41 6
7 5 0 46 6
"There are 33 minutes and 54 seconds of space left on the 80 minute CD"
Note that the output converts the input from seconds to minutes and seconds.
This is what I have so far:
Code:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
int count;
int song;
int sec;
int min;
int totalSec;
int totalMin;
ifstream indata;
indata.open("songs.dat");
if (!indata)
{
cout << "Can't open input file." <<endl;
return 1;
}
indata >> min >> sec;
cout << setw(4) << "Song" << setw(18)
<< "Song Time" << setw(18) << "Total Time" << endl;
cout << fixed << setw(2)
<< "Number" << setw(10) << "Minutes" << setw(10) << "Seconds" << setw(10)
<< "Minutes" << setw(10) << "Seconds" <<endl;
indata >> min >> sec;
I don't know how to get the information into a chart. I know I need to use a while statement, but I'm not sure how. Can anyone help me??
Thanks