Thread: "User Input" not working as intended

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    10

    Exclamation getchar() to grab the first character of a string

    Okay, I've looked through the FAQ's regarding getchar, most if it is a above my level, and the stuff that isn't does not help me at all.

    I've been working on this for the pas 6-7hrs and I'm not getting any closer to the solution than when i first started.

    /* The Situation */

    After the Patient Number check is complete, the diagnosis portion of the program begins, it is in this part i'm having this biggest problem. When the user inputs "yes" or "yupe", "nope" or "no", my program is suppose to just look at the first character of the string they inputed and determine if the response is a "Y" or "N".

    No matter which loop i used, it still doesn't work, I've tried a while, for, do/while, switch. I just don't know what is wrong with it. Anyhow, after typing e.g. "Yes", my program will display this....

    Fever ----------
    Invalid Entry.
    Fever ----------

    it is on the second Fever, that i'm allowed to actually make my first input. And when i do make and input, it will do the same thing for the next symptom....

    All i want to be able to do, is accept a string or a character as an input to the various types mentioned above, if it doesn't fall into this category, it gives a "Invalid Entry" msg, and restates the " Fever ------" prompt.

    I need something. FAQ's and Google just isn't working for me.

    Here's my complete code minus comments and beautification

    Code:
     
    
    
      
    
      printf("\nWhich of the following symptoms does the patient have (Y for yes, N for no)\n");
    
    /*********************************************************/
      /* Fever Input Response */
    
      do
       {
        printf("\n     Fever -------- ");
        getchar();
        fever_rep = toupper(getchar());
        
    
        switch(fever_rep)
          {
           case('Y') : fever = 1;
                       fCount = 1;
                       symptoms = symptoms + 1;
                       break;
           case('N') : fever = 0;
                       fCount = 1;
                       break;
             default : printf("\n   Invalid Response\n");
                       break;
          } 
       } while(fCount == 0);
    
    
    /********************************************************/
      /* Headache Input Response */
    
      do
       {
        printf("\n     Headache -------- ");
        getchar();
        headache_rep = toupper(getchar());
        
    
        switch(headache_rep)
          {
           case('Y') : headache = 1;
                       hCount = 1;
                       symptoms = symptoms + 1;
                       break;
           case('N') : headache = 0;
                       hCount = 1;
                       break;
             default : printf("\n   Invalid Response\n");
                       break;
          } 
       } while(hCount == 0);
    
    
    /**********************************************************/
    Last edited by daedenilus; 11-13-2005 at 05:08 PM. Reason: new code

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. working out...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 04-10-2003, 10:20 AM
  2. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 04:08 AM
  3. getting current working filename
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 04-17-2002, 03:42 PM
  4. What ive been working one, GL related
    By Eber Kain in forum Game Programming
    Replies: 3
    Last Post: 10-15-2001, 09:20 AM
  5. Newbie working on a lift simulation
    By dethray79 in forum C++ Programming
    Replies: 1
    Last Post: 10-07-2001, 08:28 AM