Question
One of the critical tools in solving problems via computers is the ability to execute certain instructions only when some conditions are true. To do
One of the critical tools in solving problems via computers is the ability to execute certain instructions only when some conditions are true. To do this you will need to use if-else statements. This type of statement tests for a condition, and then executes instructions based on whether the condition was TRUE or FALSE. In the following example, the user was prompted to provide a value for x. This value was then tested to determine if it was less than 5. If the user had input the value 4, they would see the output Your value 4 was less than 5. If the user had input the value 6, they would see the output Your value 6 was greater than or equal to 5.
In order to test your values you will need to use comparison operators such as:
== Tests if the value on the left is equal to the value on the right. Returns TRUE if the values are equal or FALSE if the values are not equal
> Tests if the value on the left is greater than the value on the right. Returns TRUE if the value on the left is greater than the value on the right or FALSE if the value on the left is not greater than the value on the right.
>= Tests if the value on the left is greater than or equal to the value on the right. Returns TRUE if the value on the left is greater than or equal to the value on the right or FALSE if the value on the left is not greater than or equal to the value on the right.
Modify the above program as follows.
Instead of asking the user for any integer, ask the user to enter a number between 100 and 200, inclusive.
Check whether the entered number is in the provided range o If the user-entered number is outside the range, display an error
message saying that the number is outside the range. o If the user-entered number is within a range
-
Generate a seeded random number in the range of 100 to 200, inclusive.
-
Display the randomly generated number with a suitable message.
-
Check if the generated number is less than the user entered
number
-
Inform the user with a suitable message
Once you complete your program, save the file as Lab4B.cpp, making sure it compiles and that it outputs the correct total cost for different numbers of cookies. Note that you will submit this file to Canvas.
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