I have to write a program for this homework below, but I'm stuck.I am fairly new to programming, so please help me to find a simpler way.
You are burning music CD's for a party. You've arranged a list of songs in the order you want to play them. However, you would like to maximize your use of space on the CD, which holds 80 minutes of music. So, you want to figure out the total time for a group of songs and see how they fit. Write a C++ program to help you do this. The data are on file songs.dat. The time is entered as seconds, but the output converts the seconds to minutes and seconds. After all the data has been read, the application should print a message indicating the time left on the CD. The output should be in the form of a table with columns and headings written on a file.
For example:
Song Song Time Total Time
Number Minutes Seconds Minutes Seconds
------- ------- ------- ------- -------
1 5 10 5 10
2 7 42 12 52
3 4 19 17 11
4 4 33 21 44
5 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. Use meaningful variable names, proper indentation, and appropriate comments. Thoroughly test the program using your own data sets.
code below does not work right at all: I am trying to find a much simpler way to do this problem in the first place. when it runs, "it says cant open input file, cancelling."
int main()
{
int songMinutes = 0;
int songSeconds = 0;
int timeSeconds = 0;
int totalMinutes = 0;
int totalSeconds = 0;
int minutesLeft = 0;
int secondsLeft = 0;
int totalTime = 0;
int usedTime = 0;
int current = 0;
int currentMinutes = 0;
int currentSeconds = 0;
int usedMinutes;
int usedSeconds;
int seconds = 0;
int newtotalTime = 0;
int songNumber;
bool ok = true;
Regarding the error you're getting, do you actually have songs.dat? If so, is it on your F:\ drive? If so, are you using an online compiler?
The way you're setting up your headings is too complicated. Also, it looks like they might be too long. In general, you want to keep each line at 80 characters or less for console output. You should just do something like this:
1 2 3
cout << " Song Song Time Total Time" << endl;
cout << "Number Minutes Seconds Minutes Seconds" << endl;
cout << "------ ------- ------- ------- -------" << endl;
When you're outputting data in your loop, use this: