Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!