0

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

#include <stdio.h>
#include <conio.h>
main ()
{
int a,b;
float answer;
char choice;
clrscr();
printf ("\nEnter a number: ");
scanf ("%d",&a);
printf ("\nEnter another number: ");
scanf ("%d",&b);
printf ("\n");
gotoxy(10,5);
printf("\n MENU");
printf("\n+...addition");
printf("\n*...multiplication");
printf("\n/...division");
printf("\nM...modulo division");
printf("\n");
printf("\nEnter your choice");
//scanf("%c",&choice);
choice = getch();
switch(choice)
 {case'+' :{
   answer = (a + b);
   break;
      }
  case'*' :{
    answer = (a * b);
    break;
       }
  case'/' :{
    answer = (a / b);
    break;
       }
  case'M' :{
    answer = (a % b);
    break;
     }
  default : break;
 }
printf("\n");
printf("\nThe answer is ");
printf("%d",answer);
getch();
}
2
Contributors
2
Replies
4
Views
11 Years
Discussion Span
Last Post by s88
0

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.

0

Ok thanks a lot! I really didn't see that, thanks!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.