CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 36
  1. #16
    Join Date
    Jan 2008
    Posts
    43

    Re: why is it skipping lines?

    well, like I said, I have only been working with C++ for 5 weeks. So no, I don't fully understand anything about C++. What I do no is that so far the program works and is doing what I think it should do. At this stage in the game that is good enough. Maybe after a year or so I will be able to rewrite this program with all the things you guys are talking about.

  2. #17
    Join Date
    Apr 1999
    Posts
    27,449

    Re: why is it skipping lines?

    Quote Originally Posted by CyberShot View Post
    I think I see what you are saying. I am doing it this way because I can easily understand what is going on at my level of programming.
    And the ironic thing is that you didn't really know what you were doing until we pointed it out to you. You may still not understand what you really are doing with respect to recursion.
    To do it your way would take me much more time than I have because I would have to figure it out.
    Well, isn't that what learning is about, to figure things out? In addition, if the teacher is awake, they should take points off if you handed this in -- programming isn't just getting input, calculating, and getting output. You have to make sure the program flow is correct, and using recursion is not correct.

    Besides, it probably is easier to do this non-recursively, despite your claim of it being more difficult.
    The program only needs to work once
    It doesn't work once. "Once" means that the program works from beginning to end. That is not the case with your code.

    If I sat there at the keyboard and chose choice 'A' thousands of times without exiting, your program bombs out.

    Regards,

    Paul McKenzie

  3. #18
    Join Date
    Apr 1999
    Posts
    27,449

    Re: why is it skipping lines?

    Code:
    start program
    
    do
    {
        display menu and get selection
        if ( selection is 'a') do a stuff
        if ( selection is 'b') do b stuff
    }  while (selection is not 'q') // meaning quit
    
    end program
    That is basically the pseuodocode you claim takes a lot of time to figure out.

    Regards,

    Paul McKenzie

  4. #19
    Join Date
    Jan 2008
    Posts
    43

    Re: why is it skipping lines?

    I do understand most of what you are getting at. But when you are learning, you don't learn it by knowing everything. Like I said, I only have one week for this program and beyond that, there are lots of other things that I need to do for other classes. I can't spend the entire week on it. there will be error checking that I will add in there. Right now, this is just a skeleton of the program, a rough draft kind of thing.

    what you want is for me to skip first, second and third base and go straight home. I don't have that much time.

  5. #20
    Join Date
    Apr 1999
    Posts
    27,449

    Re: why is it skipping lines?

    Quote Originally Posted by CyberShot View Post
    what you want is for me to skip first, second and third base and go straight home. I don't have that much time.
    The thing you are not understanding is that doing this the right way was easier than what you wrote. Look at my pseudo-code above.

    Using recursion is "going to home plate before reaching first base", since most beginners do not learn recursive functions and its purpose until the middle or end of their first course.

    Regards,

    Paul McKenzie

  6. #21
    Join Date
    Apr 1999
    Posts
    27,449

    Re: why is it skipping lines?

    and if you want an alternative:
    Code:
    start program
    
    set selection to 'a'
    
    while selection is not 'q'
    {
        display menu and get selection
        if ( selection is 'a') do a stuff
        if ( selection is 'b') do b stuff
    }  
    
    end program
    Regards,

    Paul McKenzie

  7. #22
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: why is it skipping lines?

    Quote Originally Posted by CyberShot View Post
    well, like I said, I have only been working with C++ for 5 weeks. So no, I don't fully understand anything about C++. What I do no is that so far the program works and is doing what I think it should do. At this stage in the game that is good enough. Maybe after a year or so I will be able to rewrite this program with all the things you guys are talking about.
    You'll still need to learn to write iterative loops correctly. Even if this program appears to work, the next one won't. You've written code that's guaranteed to crash if you loop too many times. As you say, you don't fully understand C++, so take the advice of those of us a little further down the road. Learn how to use a while loop in cases like this. It really isn't optional.

  8. #23
    Join Date
    Jan 2008
    Posts
    43

    Re: why is it skipping lines?

    I completely understand where you guys are coming from. The points you made are valid and I will look into improving my code so that it doesn't crash if you were to enter the choice 5 times then press enter. I have just tested it and I see how it crashes now.

    My point is this. Doing all that work right now would not be beneficial to my learning. You ever notice that when you are reading a programming book, it will introduce you to a subject and then say something like "But more on that in a later chapter". I am on chapter 5, 6 and 7 here. I feel like a lot of what you guys are talking about are in chapters 20, 21 and so on. I can't skip ahead and design the program to be flawless. Right now, all my instructor requires is that the program works. It doesn't need to purr like a kitten, it just needs to produce the answer he is looking for. All the error checking will come into play in later chapters.

    Your points are well taken and I will look to implement them if I can figure it out. I am researching the clear() and ignore() functions right now to see if they can clean things up a little.

  9. #24
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: why is it skipping lines?

    Hmmm.....the issue they're worried about is more fundamental to how functions work. Not quite chapter 1, but....maybe chapter 2. It's appearing that you may have a fundamental misunderstanding of how functions work, and that needs to be corrected ASAP.

    What you are trying to do is to return to the top of the selection() function if addChecksum fails. You are doing this, but in the wrong way----instead of returning control upward with an error indication, you're burrowing ever further downward.

  10. #25
    Join Date
    Jan 2008
    Posts
    43

    Re: why is it skipping lines?

    I would agree with you on the fundamental misunderstandings of functions. We are using
    C++ Programming From problem analysis to program design by D.S Malik. Functions are chapters 6 and 7. I am on chapter 7 right now which is User defined functions 2.

    I will put some thought into what you guys have said and see if I can come up with another way to write this. Maybe my instructor will have some input, I will ask him on thursday when I attend class.

    P.S When I was googling skipping getline, this post came up in the results. I thought it was funny, this site comes up quick in google
    Last edited by CyberShot; July 27th, 2010 at 02:57 PM.

  11. #26
    Join Date
    Aug 2007
    Posts
    858

    Re: why is it skipping lines?

    Quote Originally Posted by CyberShot View Post
    I do understand most of what you are getting at. But when you are learning, you don't learn it by knowing everything. Like I said, I only have one week for this program and beyond that, there are lots of other things that I need to do for other classes. I can't spend the entire week on it. there will be error checking that I will add in there. Right now, this is just a skeleton of the program, a rough draft kind of thing.

    what you want is for me to skip first, second and third base and go straight home. I don't have that much time.
    Did your instructor specifically tell you to solve the problem using recursion in this manner? If not, then what you're shooting for is probably going to be a bad grade, because you're using recursion incorrectly and have a program that's not able to execute successfully. What they're asking you to do is not high end or complicated stuff - basic flow control like a while loop should be about the second or 3rd thing taught in any decent programming class.

    If they did tell you to do it this way... then that's another problem entirely. If that's the case you have to make them happy to get the grade, but understand that they're teaching you something totally wrong.

  12. #27
    Join Date
    Apr 1999
    Posts
    27,449

    Re: why is it skipping lines?

    Quote Originally Posted by CyberShot View Post
    "But more on that in a later chapter". I am on chapter 5, 6 and 7 here. I feel like a lot of what you guys are talking about are in chapters 20, 21 and so on.
    I wouldn't think a book introduces do() and while() loops in chapter 20 -- instead they are introduced early, since you can't control flow of a program without them.

    I am sure your book introduced these to you by now, the problem is that you don't know how to use control structures properly. The psuedo-code I wrote before is not difficult at all -- that is not chapter 20 stuff to change that to real code. Since you're on chapter 7, you should be able to easily take that pseudo-code and change it to C++, if not, you didn't thoroughly understand chapters 1 through 6, and you need to re-read them again.
    Right now, all my instructor requires is that the program works. It doesn't need to purr like a kitten, it just needs to produce the answer he is looking for.
    Then that is no teacher of programming. A programming teacher also looks for structure and how you wrote the program, not if you just get the final results. As I stated earlier, if the teacher is of any worth, you using recursion would/should get points deducted from the assignment.

    Regards,

    Paul McKenzie

  13. #28
    Join Date
    Jan 2008
    Posts
    43

    Re: why is it skipping lines?

    The only idea here is to use user defined functions. Just one or two like I have. The other idea I think is to use a checksum to check the integrity of a file. The program doesn't get graded on being flawless. It gets checked to see that a few basics for the week have been implemented. Like will it check to file for integrity and print the int result of the file.

    I have attached the actual assignment for you to check out if you are interested in seeing. it gives the specifics of what the program needs to accomplish
    Attached Files Attached Files

  14. #29
    Join Date
    Aug 2007
    Posts
    858

    Re: why is it skipping lines?

    Quote Originally Posted by CyberShot View Post
    I would agree with you on the fundamental misunderstandings of functions. We are using
    C++ Programming From problem analysis to program design by D.S Malik. Functions are chapters 6 and 7. I am on chapter 7 right now which is User defined functions 2.
    Then you need to go back to Chapter 5: Control Structures II (Repetition). That's where this stuff is.

  15. #30
    Join Date
    Jan 2008
    Posts
    43

    Re: why is it skipping lines?

    well Paul I think you are right. I have read about do, while, for loops and all that. But one week isn't really enough time to fully comprehend them. Not for me anyway. Remember, I have only been at this for 5 weeks. That will not make me a pro at design. Like I said, I will take a look at your comments and try to change the program

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured