my simple calculator loops but it doesn't display the answer

hi! I'm just a beginner. Can you help me out with this simple calculator?

Here's my code. Thanks in advance! I was thinking if there is a problem with my usage of "yesorno" variable.

#include <stdio.h>
#include <conio.h>
#include <ctype.h>
void main()
{
char yesorno;
do
{

clrscr();
//initializing variables
int oper;

//displaying operations
printf ("\n\n\t[1] Addition");
printf ("\n\n\t[2] Subtraction");
printf ("\n\n\t[3] Multiplication");
printf ("\n\n\t[4] Division");

//asking for input or operation to be used
printf ("\n\n\tEnter choice: ");
scanf ("%d",&oper);

//case addition
switch (oper)
{
case 1:
//initializing variables
int a, numa1, numa2;

//asking for first input
printf ("\n\n\tEnter input 1: ");
scanf ("%d",&numa1);

//asking for second input
printf ("\n\n\tEnter input 2: ");
scanf ("%d",&numa2);

//when operation is addition
a = numa1+numa2;
printf ("\n\n\tThe sum of %d and %d is %d",numa1,numa2,a);
break;
case 2:
//initializing variables
int s, nums1, nums2;

//asking for first input
printf ("\n\n\tEnter input 1: ");
scanf ("%d",&nums1);

//asking for second input
printf ("\n\n\tEnter input 2: ");
scanf ("%d",&nums2);

//when operation is subtraction
s = nums1-nums2;
printf ("\n\n\tThe difference between %d and %d is %d",nums1,nums2,s);
break;
case 3:
//initializing variables
int m, numm1, numm2;

//asking for first input
printf ("\n\n\tEnter input 1: ");
scanf ("%d",&numm1);

//asking for second input
printf ("\n\n\tEnter input 2: ");
scanf ("%d",&numm2);

//when operation is multiplication
m = numm1*numm2;
printf ("\n\n\tThe product of %d and %d is %d",numm1,numm2,m);
break;

case 4:
//initializing variables
float d, numd1, numd2;

//asking for first input
printf ("\n\n\tEnter input 1: ");
scanf ("%f",&numd1);

//asking for second input
printf ("\n\n\tEnter input 2: ");
scanf ("%f",&numd2);

//when operation is division
d = numd1/numd2;
printf ("\n\n\tThe quotient of %.0f and %.0f is %.2f",numd1,numd2,d);
break;

default:
//when operation is not valid
printf ("\n\n\tNo equivalent operation found for %d",oper);
break;
}
printf ("\n\n\tDo you want to try again? Y/N: ");
scanf ("%s",&yesorno);
switch (tolower(yesorno));
}while (yesorno='y');

getch ();
}
Last edited on
Like you say - this line while (yesorno='y') is wrong.
Don't you mean == rather than =
Last edited on
thanks guestgulkan
Topic archived. No new replies allowed.