Thread: What's wrong w/ this code?

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    1

    What's wrong w/ this code?

    I tried writing a simple calculator in C, cause Im a real beginner. (noob) Well the issue I have is that it does not allow me to input the operator character and just skips that piece of input and ends the program.What's wrong w/ this code?-capture-jpg

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Well, for one thing it's completely out of focus...

    Post your actual code using the [code] and [/code] tags the forum provides...
    I can't even read that blurry mess...

  3. #3
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    We normally use code tags here. Please read the Posting Code Announcement.

    Your problem is because you have trailing newline characters in your input buffer from hitting the enter key. To get scanf to ignore these whitespace characters, use:
    Code:
    scanf(" %c", &z);
    Notice the space in front of the format string.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Enter-key is a perfectly good character, so when you try to read in a character, guess what character you read in? You should use the ever-popular
    Code:
    scanf(" %c", &z);
    for all your non-enter-key-reading needs.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Wow... you guys must have much better eyes than I do!

  6. #6
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by CommonTater View Post
    Wow... you guys must have much better eyes than I do!
    LOL....it's because we aren't as old as you, nor Canadian.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    And we know how to use Ctrl-+.

  8. #8
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by tabstop View Post
    And we know how to use Ctrl-+.
    You gave away the secret.....
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by AndrewHunter View Post
    LOL....it's because we aren't as old as you, nor Canadian.
    eeeeeech, your breath stinks and your mother dresses you funny...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. wad wrong with this code?
    By tantan23434 in forum C Programming
    Replies: 3
    Last Post: 10-06-2009, 11:34 PM
  2. what is wrong with my C code, PLZ help!!!
    By Eng_Girl in forum C Programming
    Replies: 5
    Last Post: 03-25-2006, 11:17 AM
  3. Is there something wrong with this code?
    By lime in forum C Programming
    Replies: 6
    Last Post: 07-28-2003, 06:17 AM
  4. What's wrong with this code?
    By chrischar in forum C Programming
    Replies: 2
    Last Post: 06-17-2003, 03:08 AM
  5. What is wrong with this code!!!
    By Troll_King in forum C Programming
    Replies: 9
    Last Post: 10-18-2001, 05:06 AM