Need help with homework assignment plz..

This is a discussion on Need help with homework assignment plz.. within the C++ Programming forums, part of the General Programming Boards category; Here's the full problem: Here's the assignment: You are burning music CD's for a party. You've arranged a list of ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    20

    Need help with homework assignment plz..

    Here's the full problem: Here's the assignment: 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
    5 4 19 17 11
    4 4 33 21 44
    3 10 27 32 11
    7 8 55 41 6
    6 5 0 46 6
    There are 33 minutes and 54 seconds of space left on the 80 minute CD.

    Here's my code so far...
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Aug 2006
    Posts
    163
    Your code is quite messy, and there's a lot of really simple errors (misspelling, missing semicolons, etc...). Did you look at your compile errors at all? They will tell you what is wrong. First you'll have to go through and fix all of that type stuff.

    Second, do you have a flow chart, or psuedo code? Using some type of design plan will help a lot when writing programs of any size.

    third, try to post your code using the [CODE] tags so that people don't have to download your files.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    Either ask a specific question or don't ask at all. Why would we be inclined to solve your homework assignments. On second thought, if you have some bucks to spare...

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    20
    How do I get the total time?? I can not do time1+time2+time3 etc. because I do not iknow how many values will be in the file..

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    A loop and a variable in which you accumulate the total.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    20
    I've ggot the loop

    Code:
    while (inData)
        {
            songmin = baseValue / 60
            songsec = baseValue % 60
            totalmin = songmin
            totalsec = songsec
            inData >> baseValue;
            totalmin = prevsongmin + songmin
            totalsec = prevsongsec + songsec

  7. #7
    Registered User
    Join Date
    Aug 2006
    Posts
    163
    First, you left out SIX semicolons in this one loop. I think you need to go back over the basics of C++ which can be found here: http://www.cprogramming.com/tutorial.html

    Try this:

    Code:
    while (inData)
        {
            songmin = baseValue / 60;
            songsec = baseValue % 60;
            totalmin += songmin;
            totalsec += songsec;   
            inData >> baseValue;
        }

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    20
    I am only getting one error now. it says that there is a syntax error before string constant. here is the line of code it is referring to..
    Code:
    cout << setw(14) << "Number" << setw(8) << "Minutes" << setw(8)
             << "Seconds" << setw(8) << "Minutes" << setw(9) "Seconds" << endl;
    Last edited by RVDFan85; 10-04-2006 at 06:25 PM.

  9. #9
    Registered User
    Join Date
    Aug 2006
    Posts
    163
    Quote Originally Posted by RVDFan85
    I am only getting one error now. it says that there is a syntax error before string constant. here is the line of code it is referring to..
    Code:
    cout << setw(14) << "Number" << setw(8) << "Minutes" << setw(8)
             << "Seconds" << setw(8) << "Minutes" << setw(9) "Seconds" << endl;
    again, this is very elementary. add << betwe setw(9) and "Seconds"

  10. #10
    Registered User
    Join Date
    Oct 2006
    Posts
    20
    Thanks again for the help. I get frustrated and try to get the assignment done, so I guess I overlook some of the more simpiler things..

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    Try pressing "compile" after every line you type.

    If you add new errors, look at the line you just typed and fix it.

    It takes 5 seconds to do, and you have instant feedback.

    Writing a whole bunch of lines and dumping it on a message board for someone else to fix your typo's isn't productive (or time-efficient) for any one.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  12. #12
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479
    On another note, take more care when you code. There is no rush. The more careful you are, the less mistakes you will make. Especially with typo's like mis-spelt variable names and missing semi-colons

  13. #13
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    I agree with swgh, you will find in time (or maybe found out already) that writting the actual code unless it is something that you have done a million times, is always going to take a lot less time than debugging and tweaking it to run exactly as you want.

  14. #14
    Registered User
    Join Date
    Oct 2006
    Posts
    20
    Quote Originally Posted by System_159
    First, you left out SIX semicolons in this one loop. I think you need to go back over the basics of C++ which can be found here: http://www.cprogramming.com/tutorial.html

    Try this:

    Code:
    while (inData)
        {
            songmin = baseValue / 60;
            songsec = baseValue % 60;
            totalmin += songmin;
            totalsec += songsec;   
            inData >> baseValue;
        }
    ok... so based on that code, how do I get the final time and subtract it from 80 to get the time remaining on the CD..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 10:19 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  3. Replies: 1
    Last Post: 10-27-2006, 02:21 PM
  4. Frustration with Homework assignment
    By Jake in forum C++ Programming
    Replies: 3
    Last Post: 10-31-2001, 01:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21