Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Vibhor16

  • 4 years ago

Can some one debug it pls.. #include<stdio.h> int main() { int one,two,ans=0; char sym; printf("Enter a number: "); scanf("%d/n",&"%d/n",&one); printf("Enter another number :"); scanf("%d/n",&two); printf("Enter an operator(+,-,*,/): "); scanf("%ch/n",&sym); if(sym=='+') ans=one+two; else if(sym=='-') ans=one-two; else if(sym=='*') ans=one*two; else ans=one/two; printf("The result is: ",ans); getch(); return 0; } It always show same result i.e -7188

  • This Question is Closed
  1. agdgdgdgwngo
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    scanf("%d\n", &"%d\n", $one); is this a typo?

  2. agdgdgdgwngo
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    also scanf("%ch\n", &sym); %c is the correct conversion specifier and not %ch :-(

  3. agdgdgdgwngo
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    instead of that line, you can use sym = getchar()

  4. agdgdgdgwngo
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    Finally, you've got printf("The result is: ", ans) with no %d conversion specifier in the format string.

  5. Vibhor16
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    C is a lot complicated than C++. :P

  6. agdgdgdgwngo
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    not really. It's just that scanf() is so inconvenient

  7. Vibhor16
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    now it shows 4+4=1

  8. agdgdgdgwngo
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    http://ideone.com/bTFbT

  9. agdgdgdgwngo
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    hahaha I have a bug in there: one / 2 instead of one / two :-P

  10. agdgdgdgwngo
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    http://ideone.com/xCtvs

  11. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy