Thread: help with ending program

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    7

    help with ending program

    Hi guys, Derek here to pick your brains once more.

    My program is a currency conversion program. Everything works the way I want it to except one small thing.

    At the menu selection, if the user selects a wrong number, the error checking and loop work as it should, giving the user the choice of trying again.

    But if the user enters a character instead....well it displays the error message with the choices, but instead of waiting for the user to make a choice, the program ends.

    The program meets the requirements for the assignment, and I have already turned it in...but I pay big money for college and I want to learn, so this would be for my own edification. So please, would one of you kindly take a look at it, maybe even give it a b/c/exe and see what you think I could do. Im totally open to suggestions.


    Instead of cluttering up this post with my code, I thought it would be more efficient and easier if I simply posted a link to it, where you can easily view the whole thing.

    You can get the code here

    im a newbie but Im willing to learn.

    greetz

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You're mising scanf and get*() calls. That's the cause of your problem. I'd be willing to bet this is covered in the FAQ, were you actually to take the time to read it.

    scanf tends to leave the newline character in the buffer, and so your next call is reading this as a keystroke.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    7
    I'd be willing to bet this is covered in the FAQ, were you actually to take the time to read it.
    did you take the time to read it?

    im new ok. have I put forth effort? hell yeah I have. I staued up until 5 am last night ok!! I read the FAQ. I searched the forums. I searched the the text I have. I emailed my classmates. I tried different stuff.

    I have spent hours reading the various FAQ. this is the exact reason why in my first post here I said I was terrified of you guys, cuz if I asked a question I would get reamed for 'not looking it up' or 'not doing a search' or whatever.

    well guess what, some of this is kinda cryptic to me. Im new to programming in C. I know very little about it compared to all the Gods that are to be found here.

    Have I put forth effort ? YES I HAVE. Thats why I stayed up till 5 am trying different things to get this to work exactly as I want it.

    I had this damn thing working good enough for the assignment as of 6.21.03. Thats when I turned it in, ok. I turned it in, and have accepted the B grade I got on it. The class is over, and I got an A...3 credits more towards my bachelors.

    But no...I decided to try and figure out how to make it work the way I really really wanted it to.

    yeah I searched the FAQ. I searched the forums. Ya know what I found? COUNTLESS responses just like this. COUNTLESS people who just want a little straight help, instead they get insulted for their newbishness. So I missed a little detail...is that fair reason to assume that Im not 'taking the time' ???

    You have no FREAKIN CLUE how much time I have spent trying to get it right, I came here out of desperation..I thought I asked my question properly, but NO i get insulted...welll screw u.

    And you dont even know for sure if its in the FAQ or not, do you? DO YOU! NO you DONT you just assume its in there cuz OH iTS sO SIMPle HoW COulD this NEWB ask me this simple question. Well I searched, ok, I Looked...and if it was in there, I missed it cuz I didnt understand the answer, and I wanted to ask for some laymans terms.

    But tooo friggin high and mighty arent you. Wel guess what. I did search the forums, and I was terrrified of this exact thing. I have read COUNTLESS posts where you guys go after someone cuz they arent putting forth the effort or whatever.


    You should all go work for microsoft. and you should all be ashamed of yourselves. I put forth lots of effort. if its to much fuggin trouble for you to help me out, what the FRUCK are you replying for? you think your high and mighty insults help anyone?


    good bye. I dont need this kind of bullcrap. I didnt ask for the pious slop I just received. All of you. You make it seem like we should know this $$$$. Why the FRUCK would we come here and ask if we knew already?!!? HUH?

    buncha diks. how dare you. get off your damn high horse. it wont be me, cuz Im evidently not smart enough nor do I put out the effort...but watch yourselves you dont get ddos or something for ........ing on the wrong person. u all think you are so smart.

    delete my thread. i dont care. but you know the words I speak are true.

    signed,
    someone who honestly worked hard, and tried to get help

  4. #4
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    calm down there big guy. Nobody is going to delete your thread, and if you just wait for people to get the chance to post a more detailed answer to your problem. Sometimes it takes a couple days for the right person to read it. Just sit back, and don't worry. We're friendly people who just like to post links to FAQs and Google when it seems that someone isn't trying - but it appears that you are.
    Away.

  5. #5
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    Did you have any more questions Derek?
    The keyboard is the standard device used to cause computer errors!

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Oh how foolish of me! What was I thinking? I mean, this problem never occurs around here. I mean, it's not like I am the only one who actually answered your question. As for the FAQ, it is actually covered in this one here. But I guess I should memorize every FAQ out there so I can point you directly at it. $$$$ off.

    [edit]
    And if that isn't enough for you, here's some more you can read, since you searched so much. It took me a whole two seconds and the search button to find your answer. It's not like I used some "super secret keywords" either. "scanf" "wait". I must be a god damn search engine wizard.
    [/edit]

    Quzah.
    Last edited by quzah; 06-24-2003 at 11:21 PM.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    Jun 2003
    Posts
    7
    ok so how am I supposed to know I should search for scanf and wait? hmmm?

    you just posted all kinds of links quzah. ok. so I looked at them. ok. so you dotn friggen speak english do you.


    i said before Im a newbie. if you are so burned out on helpin people out around here, why do you bother? seriously!!! come on!!

    look, im a complete newb at this, and I came here for help. I dont speaka C language ok. Im trying. but you know what, fook it, I dont need this sheet.

    look quZah, I tried to say it nice. no. you arent the only one who answered my question. many have answered it, im quite sure. but I didnt get it...ok?

    tell me something...DID YOU EVER ACTUALLY LEARN THIS LANGUAGE OR WERE YOU JUST BORN ELITE? if you cant handle 'wasting your time' with the newb questions, why bother? hmmm? how am I supposed to know I should search for scanf and wait? hmmmm? i suppose if I knew a bit about C then I would search for that. but since I have been doing C for all of TWO FOOKIN WEEKS i suppose maybe I could get cut a little slack.

    No one here speaks english. all you do is insult those who stop by lookin for help.

    what about the guy that is honestly trying, but just doesnt get it? all the links you posted for me...everyone of them....they are all greek to me. I dont "speak" the language ok. am I stupid? maybe so. how about just saying that instead of assuming I didnt look. I spent fookin DAYS lookin for answers...I lost SLEEP over it.


    as for
    this FAQ that I so blatantly missed to be honest, it looks like greek to me. and yeah, if I had used the words scanf or wait in my search, maybe i woulda found it. but go figure.....THATS WHAT I WAS MISSING SO GEEE...I DIDNT THINK TO SEARCH FOR IT.


    what a shame. seems like some of you are nice guys. to bad that others here cant look down from their mountain and have mercy on the mortals. looks like some of the GODS forgot what it was like to be just a lowly beginner.

    wtf is the point of this site if all you do is refer people to books or faqs that they already read. if it made sense in the FAQ or the book, why would I post?

    signing out, for good, cuz its clear I dont belong or am to stupid...

    Derek
    Last edited by Derek; 06-25-2003 at 01:43 AM.

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Derek
    you arent the only one who answered my question. many have answered it, im quite sure. but I didnt get it...ok?
    Oh really? What did you do then, post this same question over and over in different threads? Because from where I'm sitting, there is one reply here telling you what your problem was, and that's mine.

    Go on smart ass, look again. Yep, that's me. What was the first thing I said? I said it's because you were mixing scanf and get*() calls. There, the first sentence I typed answered your question. My final sentence also answered your question.

    Did I get a thanks? No. You started crying about how I didn't sugar coat my answer for you.


    Originally posted by Derek
    if it made sense in the FAQ or the book, why would I post?

    signing out, for good, cuz its clear I dont belong or am to stupid...

    Derek
    Your problem is you get your panties in a bunch when someone doesn't kowtow to you. You didn't ask for clarification. You went off on me because you didn't like my answer. My answer clearly stated what the problem was. Here, let me say it again, read slowly this time:

    You mixed scanf() and get*() function calls. Scanf leaves the newline in the buffer. A new line is the '\n' character. If you don't know what that is, it's what happens when you hit enter.

    God I love repeating myself. Apparently you do also, because your last post says the exact same thing three times in three pharagraphs.

    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    Registered User
    Join Date
    Jun 2003
    Posts
    70
    Problem is here:

    > scanf("%i",&i); //begin case selection

    If scanf is used for taking in integer value and user gives something else, variable's previous value never changed.

    In your code you do not have initialize variable 'i' with any value.
    Initialize it with value 1. Now if user give character input it will defaulty conver dollar's value to british pound.

  10. #10
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    This is brilliant!

  11. #11
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by cr_naik
    Problem is here:

    > scanf("%i",&i); //begin case selection

    If scanf is used for taking in integer value and user gives something else, variable's previous value never changed.

    In your code you do not have initialize variable 'i' with any value.
    Initialize it with value 1. Now if user give character input it will defaulty conver dollar's value to british pound.
    They should be checking the return value of scanf, but that isn't the problem.

    I have already explained what the actual problem was. They just didn't care to hear it. Good effort though.

    Quzah.
    Hope is the first step on the road to disappointment.

  12. #12
    Registered User
    Join Date
    Jun 2003
    Posts
    70
    >The quick-fix for the newline problem is
    scanf("%i",&i); //begin case selection
    while (getchar() != '\n'); // add this to remove trailing newline


    I think there is not a newline problem. Problem is only because of invalid input.
    Chintan R Naik

  13. #13
    Registered User
    Join Date
    Apr 2003
    Posts
    31

    I am not very sure if have understood your Q

    Hi

    I think the the solution is
    to add the library
    # include< conio.h>
    the write before the scanf statement
    this
    fflush(stdin);
    to free the Buffer memory

    bye

  14. #14
    Registered User
    Join Date
    Apr 2003
    Posts
    12
    I havn't read your code, but one thing I like to use is atoi(). I use that if i use gets in my code, so I don't need to use scanf. atoi() stands for alpha to integer i believe, so instead of using scanf to get an integer you could use gets and then use atoi() to convert the string into an integer.


    Code:
    #include <stdlib.h>
    int atoi(const char *str);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  4. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM