Question
< C programming> This assignment focuses on creating andmanipulating selection control structures. The user will enter an expression (arithmetic, logical, or relational) and you will
< C programming>
This assignment focuses on creating andmanipulating selection control structures. The user will enter an expression (arithmetic, logical, or relational) and you will display the result of the expression.
Instructions
Create a program called selection.c that does the following:
Prompt for and accept an expression of the form: (axb)y(czd) ( stands for space) where a, b, c, and d are integer values; x, y, z are single characters representing operators; and the parentheses and spaces are entered as shown
There are three categories of operators that may be entered for the x, y, and z values:
Arithmetic operators: +, -, *, /, and %
Single-character relational operators: < and >
Single-character versions of the C logical operators:
& for && (logical AND)
| for || (logical OR)
! for logical NOT
Verify that all operators (the x, y, and z values) are of the same category. If the user enters operators of different categories issues an appropriate error message and end the program
Evaluate the expression and display the result
If the user entered arithmetic operators the result should be an integer value
If the user entered a relational or logical expression the result should be displayed as the string true or the string false
Your program must adhere to the class coding standards, and will be graded using the assignment grading criteria. Submit your source code file to the Desire2Learn dropbox for this assignment.
Sample Output (Several executions of the program)
Program: Selection Author: Doug Jones Enter an expression: (2 + 4) * (3 - 4) Result: (2 + 4) * (3 - 4) = -6 Program: Selection Author: Doug Jones Enter an expression: (2 > 4) * (3 < 4) Result: (2 > 4) * (3 < 4) is not a valid expression for this program
Program: Selection Author: Doug Jones Enter an expression: (4 < 4) > (3 > 3) Result: (4 < 4) > (3 > 3) = false Program: Selection Author: Doug Jones Enter an expression: (0 & 1) | (1 & 1) Result: (0 & 1) | (1 & 1) = true
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