Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

Students also viewed these Databases questions

Question

3. Job rotation is used for all levels and types of employees.

Answered: 1 week ago