Write a simple program that can perform arithmetic operations (+, -, * and \) of two integers and display the result of each operation. Ask user to select which arithmetic operration to perform. Each arithmetic operation has to be performed in a function.
here is my answer:
#include<stdio.h>
#include<conio.h>
#include<math.h>
float calculate(float x,float y);
int main()
{
float x,y;
char operation;
printf("please key in value of x and y: \n");
scanf("%f%f",&x,&y);
printf("please enter the operation you want to perform (+, -, *, /):\n");
scanf("%s",&operation);
calculate(x,y);
getch();
return 0;
}
float calculate(float x,float y)
{
if (char operation = '+')
{
float add=x+y;
printf("the sum is %f+%f=%f\n",x,y,add);
}
else if (char operation = '-')
{
float subt=x-y;
printf("the subtraction is %f-%f=%f\n",x,y,subt);
}
else if (char operation = '*')
{
float mult=x*y;
printf("the multiplication is %f*%f=%f\n",x,y,mult);
}
else if (char operation = '/')
{
float div=x/y;
printf("the division is %f/%f=%f\n",x,y,div);
}
return 0;
}
but yet.. i still can't get what i want... =(
Anyone can help me???