Like Tree1Likes
  • 1 Post By camel-man

Simple C program issue...

This is a discussion on Simple C program issue... within the C Programming forums, part of the General Programming Boards category; Unfortunately, I do not know many of the technical terms that would probably allow me to explain my issue a ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    4

    Simple C program issue...

    Unfortunately, I do not know many of the technical terms that would probably allow me to explain my issue a lot easier...but here is what my problem is...

    I want my program to take a character input and depending on the char value, it will determine an integer value to be used in an equation.

    My issue is that my program prints the correct statement to direct the user but does not allow the user to input a character.

    Code:
    //example
    
    {
    float final_value
    char multiplier
    
    printf("To multiply value by 2, enter (A), to multiply value by 20, enter (B)\n");
    scanf("%c", &multiplier);
    
    if(multiplier == 'A')
    final_value = 2 * 20;
    
    if(multiplier == 'B')
    final_value = 20 * 20;
    }
    This is just a snippet of my actual program. My program compiles fine and runs fine up until this string.

  2. #2
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    589
    Is this the whole program so far? What might be your problem, if this is in the middle of your program somewhere, is that scanf is eating up the newline character left in the buffer. You can try this little technique to see if it makes a difference.

    Code:
    scanf(" %c", &multiplier);
    Take note of the white space between the " and %.
    mbxs3 likes this.

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    4
    Thanks camel-man! That space did the trick.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A simple Array issue
    By TastySauceCode in forum C++ Programming
    Replies: 11
    Last Post: 09-22-2011, 06:02 AM
  2. simple programming issue!
    By ke121885 in forum C Programming
    Replies: 5
    Last Post: 09-27-2009, 06:57 PM
  3. Simple issue please help
    By te5la in forum C++ Programming
    Replies: 5
    Last Post: 09-17-2008, 12:11 PM
  4. Simple issue with bytes
    By Nositi in forum C Programming
    Replies: 6
    Last Post: 03-25-2008, 11:06 AM
  5. Simple issue but I am STUCK
    By jedispy in forum C++ Programming
    Replies: 2
    Last Post: 12-01-2006, 01:02 AM

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