Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Program Coded in C PHASE 1: Algorithm think through the logic on paper or as comments in your source file PHASE 2: Code Part 1

Program Coded in C

PHASE 1: Algorithm think through the logic on paper or as comments in your source file

PHASE 2: Code Part 1 start to transform your algorithm into code a. Start with the initial functionality:

The first step is to choose from the jar that is labeled both.

What did you get? a (for apple) or o (for orange): A

You chose an apple, which means that:

1. The jar that is labeled as both is really apples.

2. The jar labeled as oranges is really both.

3. The jar labeled as apples is really oranges.

Once that works, add code so that it works with either the lower or upper case letter a or A. Re-run the program and make sure it works for both.

PHASE 3: Code Part 2 a. Then, add the code to your program so that it forces valid input (new code in red below):

The first step is to choose from the jar that is labeled both.

What did you get? a (for apple) or o (for orange): k

Invalid input. Make another choice.

What did you get? a (for apple) or o (for orange): a

You chose an apple, which means that:

1. The jar that is labeled as both is really apples.

2. The jar labeled as oranges is really both.

3. The jar labeled as apples is really oranges.

PHASE 4: Code Part 3 a. Once all of the above works, you have a working program, except that if the user wants to try again starting with oranges instead of apples, they would have to re-run the executable again. Add code (a loop) so that the user is given the choice of going again without having to restart the program

The first step is to choose from the jar that is labeled both.

What did you get? a (for apple) or o (for orange): k

Invalid input. Make another choice.

What did you get? a (for apple) or o (for orange): A

You chose an apple, which means that:

1. The jar that is labeled as both is really apples.

2. The jar labeled as oranges is really both.

3. The jar labeled as apples is really oranges.

Let's try a different sequence Choose from the jar that is labeled both.

What did you get? a (for apple) or o (for orange) or q (for quit): o

You chose an orange, which means that:

1. The jar that is labeled as both is really oranges.

2. The jar labeled as apples is really both.

3. The jar labeled as oranges is really apples.

Let's try a different sequence Choose from the jar that is labeled both.

What did you get? a (for apple) or o (for orange) or q (for quit): D

Invalid input. Make another choice.

What did you get? a (for apple) or o (for orange) or q (for quit): q

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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