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();
}

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.