Question: C++ Write a program that reads the value of variable x from the user and calculates the value of the function f(x) based on the

C++
Write a program that reads the value of variable x from the user and calculates the value of the function f(x) based on the following rules: If x is positive: 3x-1 f(x) X-2 Otherwise: 5-x f(x) = 1 + You need to make sure that your program does not divide by zero. Sample outputs: Enter a double value for x: 4 f(4) = 5.5 Enter a double value for x: 2 Cannot divide by zero! Enter a double value for x: 0 Cannot divide by zero! Enter a double value for x: -2 f(-2) = -2.5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
