Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

create a C program which allows the user to enter an arithmetic expression of arbitrary length, and which calculates and outputs the value of that

create a C program which allows the user to enter an arithmetic expression of arbitrary length, and which calculates and outputs the value of that expression. The expression may consist of numeric literals (floating point values), as well as the two arithmetic operators addition and subtraction, but no parentheses. The result output by the program need not be formatted to a specific number of decimal places. Your program will validate the user's input. If the user inputs a formula which is not well-formed, your program will report the error message "malformed expression" and end immediately with a return value of 1. Otherwise, the return value should be 0.

Example sample run (input in bold):

$ gcc -std=c99 -pedantic -Wall -Wextra arithmetic.c

$ ./a.out

Please enter an arithmetic expression:

5.25

5.250000

$ ./a.out

Please enter an arithmetic expression:

3+

4-2

5.000000

$ ./a.out

Please enter an arithmetic expression:

100 - 5 + 20 + -50

65.000000

$ ./a.out

Please enter an arithmetic expression:

20 + - 50

malformed formula

$ ./a.out

Please enter an arithmetic expression:

3 4

malformed formula

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

Students also viewed these Databases questions