Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, we will construct a program that performs the basic arithmetic operations on two integer inputs. The program will present the user with

In this assignment, we will construct a program that performs the basic arithmetic operations on two integer inputs. The program will present the user with a series of prompts for the integer inputs along with the desired mathematical operation. It will display a mathematical equation that reflects the provided inputs.

When completing this assignment, the student should demonstrate mastery of the following concepts:

Conditional Logic (if, if-else, if-else-if chains)

Conditional Logic (switch/case)

Type-Casting & Type Promotions (implicit and explicit)

Phantom Character Processing

Input Bounds Checking

Assignment Write a C program that performs the five basic integer arithmetic operations on two input numbers. The program should begin by accepting two integer inputs with values on the closed interval [-1000, 1000]. This restraint should be enforced by performing the appropriate bounds checking. The program should then present a menu that allows the user to select an integer operation (addition, subtraction, multiplication, division or modulus). Again, appropriate bounds checking should be performed on this menu selection. The program performs the indicated operation on the two input numbers and displays the result in an attractive display. The following sample inputs would be appropriate for the beginnings of a test of the solution developed:

Operation | Operand #1 | Operand #2

Trial #1 | Division | 10 | 3

Trial #2 | Modulus | -23 | 4

Trial #3 | Subtraction | 999 | -1024

Your program must incorporate ALL of the following programming concepts: 1.) at least one if, if-else, or if-else chain flow control structure 2.) at least one switch-case flow control structure 3.) at least one example of integer bounds checking 4.) at least one example of explicit type-casting 5.) at least one example of handling the phantom enter key

Your program must conform to the following restrictions: 1.) You may only use the printf() and scanf() functions for input and output. 2.) You must include at least one example of accepting integer input and at least one example of accepting character input (use both the %d and %c conversion characters with scanf() ). 3.) When invalid input is supplied to the program, the program should re-prompt if possible. Some inputs will always crash your program at this point and can be disregarded (i.e. providing alphabetic inputs on a %d conversion), but many items can be addressed at this point (i.e. integer bounds checking).

Additional Notes 1.) You may assume that the user will type in integer values when prompted to do so. You may not make any assumptions about the values of the integers the user types in. 2.) You should include logic that handles certain exceptional cases. For example, division by the integer 0 is not allowed in mathematics. Your program should account for this and respond accordingly (provide an informative error message, re-prompt if necessary, and NOT CRASH). 3.) Although the inputs to the programs are integers, the result of the operation may contain a decimal value (for example 9/2 = 4.5). Your program should display decimal answers with 4 digits following the decimal point.

QUESTIONS After you have written your solution, answer the following question in a comment beneath your source code as part of the documentation: 1.) Use your program to determine the rules about the modulus operator and signs. Obviously, the modulus operation is allowed on both positive and negative integers. How does the computer determine the sign of the answer to a modulus expression based on the signs of the operands? Based on your discovery, evaluate the following expressions: a.) 9 % 2 = ??? b.) -9 % 2 = ??? c.) 9 % -2 = ??? d.) -9 % -2 = ??

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_2

Step: 3

blur-text-image_3

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 Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

More Books

Students also viewed these Databases questions