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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started