Question: My task for my coding homework was to ask the user for a function and give an output. I got everything to work except the

My task for my coding homework was to ask the user for a function and give an output. I got everything to work except the division that I had to use a double on. The outcome is always 0, can you point out what I did wrong while using the same style I put in?

int main() { int a, b, iresult; double dresult; char input; printf("Hello, my name is . Student ID "); printf("Enter two values and a basic math sign inbetween, such as; +; -; *; /; %% : "); scanf("%d%c%d", &a, &input, &b);

//5%3 modulus == % // add (double) for division if (input == '+') { iresult = a + b; printf("The sum of %d and %d is %d ", a, b, iresult); }

else if (input == '-') { iresult = a - b; printf("The difference of %d and %d is %d ", a, b, iresult); }

else if (input == '*') { iresult = a * b; printf("The product of %d and %d is %d ", a, b, iresult); }

else if (input == '/') { dresult = (double)a / b; printf("The quotient of %d and %d is %d ", a, b, dresult); }

else if (input == '%') { iresult = a % b; printf("The remainder of %d and %d is %d ", a, b, iresult); } return(0); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!