Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose you ve been asked to write a segment of code that determines the cost of riding the bus based on the value of a

Suppose youve been asked to write a segment of code that determines the cost of riding the bus based on the value of a variable age of type int. (You may assume age is nonnegative.) If age is less than 18, the cost is $1.50. If age is 65 or more, the cost is $2.00. For all other values of age, the cost is $2.50.
A friend of yours submitted the following code, and the instructor knocked off marks for "inappropriate use of branching constructs and redundant Boolean expressions". Rewrite the code in light of the comments from the instructor. You should only change lines 1,3 and 5, the other lines should remain unchanged. Do not change the order in which the comparisons are made, and do not introduce blocks ({}).

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

More Books

Students also viewed these Databases questions