Thread: error msg instead of the result so far

  1. #16
    Resu Deretsiger Nightowl's Avatar
    Join Date
    Nov 2008
    Location
    /dev/null
    Posts
    186
    while(!is_roman(rdigit) && !IS_WHITE_SPACE(rdigit) && rdigit != EOF) return 0;
    Sure, that handles it at the beginning. Not at the end.

    Just walk through it yourself with a debugger. Watch what happens when you enter an invalid roman numeral after some valid ones.

    Also, if you come back to the problem with a fresh set of eyes after a bit of a drink and rest, sometimes it helps.
    Do as I say, not as I do . . .

    Experimentation is the essence of programming. Just remember to make a backup first.

    "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF

    Questions posted by these guidelines are more likely to be answered.

    Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.

  2. #17
    Registered User
    Join Date
    Mar 2009
    Posts
    30
    Hmm. I know.
    I worked on this yesterday afternoon for like 5 hours.
    now for 3 more. still can't get this thing to work.
    I found something though,
    it seems like if i enter XXXXA, it prints 40.
    if i enter XXXXAA, it prints 40 then error msg.
    if i enter XXXXAAAA, it prints 40, then error, flush the rest.

    All my programs like to skip things on me.

  3. #18
    Registered User
    Join Date
    Mar 2009
    Posts
    30
    Seems like you are right.
    I moved the statement if it's not roman down with the statement EOF, it works now....
    I'm gonna test more data, hopefully it works for everything!

  4. #19
    Resu Deretsiger Nightowl's Avatar
    Join Date
    Nov 2008
    Location
    /dev/null
    Posts
    186
    Good to hear.

    Let us know if something else goes wrong.

    Remember: when in doubt, isolate the problem. If it's not comparing something properly, check both sides. If it's not printing errors, check the condition to print the errors. :P
    Do as I say, not as I do . . .

    Experimentation is the essence of programming. Just remember to make a backup first.

    "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF

    Questions posted by these guidelines are more likely to be answered.

    Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.

  5. #20
    Registered User
    Join Date
    Mar 2009
    Posts
    30
    I just have one question.
    Why does it make a difference?
    It's in the same function!!!

  6. #21
    Resu Deretsiger Nightowl's Avatar
    Join Date
    Nov 2008
    Location
    /dev/null
    Posts
    186
    Because above, it's outside the loop, and only runs once.

    When it's inside the loop, it runs every time the user enters something. Otherwise, outside the loop, it only gets executed whenever the function is, once per call of the function. Suboptimal, no?
    Do as I say, not as I do . . .

    Experimentation is the essence of programming. Just remember to make a backup first.

    "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF

    Questions posted by these guidelines are more likely to be answered.

    Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.

  7. #22
    Registered User
    Join Date
    Mar 2009
    Posts
    30

    Thumbs up

    gotcha!
    Thanks so much

  8. #23
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It's best if you actually make a flowchart for your code. Good for beginners.
    Make it up exactly as you need the code to behave, then translate it to code.
    Likewise, if it isn't working, then translate the code to a flowchart, make the necessary changes and translate it back.

    Also, this type of code...
    Code:
    if (x)
    { a;
    b; }
    ...is horrible to read, and thus not a good idea to do so. It's so easy to miss the last }.
    Instead, do something like...
    Code:
    if (x)
    {
        a;
        b;
    }
    Or if you REALLY, REALLY, REALLY want to save a line, you can do
    Code:
    if (x) {
        a;
        b;
    }
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #24
    Resu Deretsiger Nightowl's Avatar
    Join Date
    Nov 2008
    Location
    /dev/null
    Posts
    186
    As I pointed out in maybabier's other thread, there is a good guide to indentation here.

    It really helps with debugging, trust me. The extra 20 seconds it takes to indent everything to the proper indentation level etc, often saves 20 minutes of frustration later on.

    Anyhow, good luck with everything.
    Do as I say, not as I do . . .

    Experimentation is the essence of programming. Just remember to make a backup first.

    "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF

    Questions posted by these guidelines are more likely to be answered.

    Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.

  10. #25
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Except it will require logging in.
    http://apps.sourceforge.net/mediawik...le=Indentation
    Remove the "s" from the http and even guests can view it
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #26
    Registered User
    Join Date
    Mar 2009
    Posts
    30
    ohh you guys are so helpful.
    i usually am really neat about how i write the codes,
    but when i get frustrated i just add on and erase where ever till i get it to work then fix it.

    about debugging,
    where do you usually put them?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. Need help with basic calculation program.
    By StateofMind in forum C Programming
    Replies: 18
    Last Post: 03-06-2009, 01:44 AM
  3. Promblem with code
    By watchdogger in forum C Programming
    Replies: 18
    Last Post: 01-31-2009, 06:36 PM
  4. Can someone help with my seg fault?
    By John_L in forum C++ Programming
    Replies: 23
    Last Post: 03-01-2008, 04:04 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM