I decided to make a calcutor using code but my program just wont work. When i enter my operand and new number it wont seem to scan the operand and number and it wont start the loop. Thanks for the help.
#include <stdio.h>
#include <math.h>
float add(float x,float y);
float sub(float x,float y);
float div(float x,float y);
float exp(float x,float y);
float mult(float x,float y);
int main(){
float y,x;
char op;
printf("Type in a number\n");
scanf("%f",&x);
printf("Type in your operand and desired number\n");
scanf("%c",&op);
scanf("%f",&y);
while (!(op=='q')){
if(op=='+'){
printf("Your result is %.1f\n",add(x,y));
scanf("%c",&op);
scanf("%f",&y);
}
else if(op=='-'){
printf("Your result is %.1f\n",sub(x,y));
scanf("%c",&op);
scanf("%f",&y);
}
else if(op=='*'){
printf("Your result is %.1f\n",mult(x,y));
scanf("%c",&op);
scanf("%f",&y);
}
else if(op=='/'){
printf("Your result is %.1f\n",div(x,y));
scanf("%c",&op);
scanf("%f",&y);
}
else if(op=='^'){
printf("Your result is %.1f\n",exp(x,y));
scanf("%c",&op);
scanf("%f",&y);
}
}
printf("Your final result is %.1f\n",x);
return(0);
}
float add(float x,float y){
return (x+y);
}
float sub(float x,float y){
return (x-y);
}
float div(float x,float y){
return (x/y);
}
float exp(float x,float y){
x=pow(x,y);
return(x);
}
float mult(float x,float y){
return (x*y);
}