Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Vibhor16

  • 2 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
    • 2 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
    • 2 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
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

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

  4. agdgdgdgwngo
    • 2 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
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

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

  6. agdgdgdgwngo
    • 2 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
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    now it shows 4+4=1

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

    http://ideone.com/bTFbT

  9. agdgdgdgwngo
    • 2 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
    • 2 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.

    Search OpenStudy
    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.