User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 402,375 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,106 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 1454 | Replies: 2 | Solved
Reply
Join Date: Oct 2006
Posts: 10
Reputation: s88 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
s88 s88 is offline Offline
Newbie Poster

Help creating a menu with C problem!!

  #1  
Oct 27th, 2006
The problem is that when I enter the choice, nothing happens and the answer remains 0. Please help I'm new at this and I tried everything!!

Thanks

  1. #include <stdio.h>
  2. #include <conio.h>
  3. main ()
  4. {
  5. int a,b;
  6. float answer;
  7. char choice;
  8. clrscr();
  9. printf ("\nEnter a number: ");
  10. scanf ("%d",&a);
  11. printf ("\nEnter another number: ");
  12. scanf ("%d",&b);
  13. printf ("\n");
  14. gotoxy(10,5);
  15. printf("\n MENU");
  16. printf("\n+...addition");
  17. printf("\n*...multiplication");
  18. printf("\n/...division");
  19. printf("\nM...modulo division");
  20. printf("\n");
  21. printf("\nEnter your choice");
  22. //scanf("%c",&choice);
  23. choice = getch();
  24. switch(choice)
  25. {case'+' :{
  26. answer = (a + b);
  27. break;
  28. }
  29. case'*' :{
  30. answer = (a * b);
  31. break;
  32. }
  33. case'/' :{
  34. answer = (a / b);
  35. break;
  36. }
  37. case'M' :{
  38. answer = (a % b);
  39. break;
  40. }
  41. default : break;
  42. }
  43. printf("\n");
  44. printf("\nThe answer is ");
  45. printf("%d",answer);
  46. getch();
  47. }
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Location: Novi Sad, Serbia
Posts: 273
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Rep Power: 6
Solved Threads: 29
andor's Avatar
andor andor is offline Offline
Posting Whiz in Training

Re: creating a menu with C problem!!

  #2  
Oct 27th, 2006
Variable answer is float not int. Instead of printf("%d",answer); use printf("%f",answer); instead. Dont use nonstandard func (use them only if your teacher explicitly demanded). You need a getchar in front of choice input. Use int main and not main.
Last edited by andor : Oct 27th, 2006 at 7:49 am.
If you want to win, you must not loose (Alan Ford)
Reply With Quote  
Join Date: Oct 2006
Posts: 10
Reputation: s88 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
s88 s88 is offline Offline
Newbie Poster

Re: creating a menu with C problem!!

  #3  
Oct 27th, 2006
Ok thanks a lot! I really didn't see that, thanks!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 12:37 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC