Question: Assignment #3 Introduction to C Programming COP 3223 Objectives 1. To reinforce the use of If-Else statements 2. To learn how to use while loops

Assignment #3

Introduction to C Programming COP 3223

Objectives 1. To reinforce the use of If-Else statements 2. To learn how to use while loops

Introduction: Pirate Time Your friend has not stopped talking about how cool pirates and how awesome it would be if they could be a real-life pirate captain! To amuse your friend, you have decided to create a series of programs about pirates.

Problem: Outfitting the Crew Now that your friend has a crew, they will need to outfit them with enough gear to get them to the Caribbean and support them through obtaining treasure. In their home port, your friend can purchase new gear or used gear. New gear is more expensive, but will last longer. If you can find quality used gear, it will be more cost effective.

Your program should prompt the user with the following menu:

1) Buy New Gear

2) Buy Used Gear

3) Quit

If your friend would like to buy gear (either new or used), you should next ask how many pieces of gear they would like to buy. The price of gear is pre-determined using the following values:

Used gear sells for 5 gold pieces.

New gear sells for 15 gold pieces.

Your program must keep track of the total amount that your friend will spend for their gear. This total should be printed out when your friend decides to quit buying gear. You should also print how many pieces of new gear they obtained, how many pieces of used gear they obtained, and the average cost per piece of gear for their crew. If your friend quits before buying anything; print that their final cost will be 0 gold pieces and that they bought 0 pieces of gear. Do not print an average in this case. If the user inputs an invalid menu choice, your program should tell them that their choice is invalid and present the menu again.

Input Specification 1. All input values will be integers. 2 Output Specification Output the results using the format below: Your total cost is X gold pieces. You obtained Y pieces of new gear and Z pieces of used gear. The average cost per piece of gear is A.AA pieces of gold.

Output Samples Below are some sample outputs of running the program. Note that these samples are NOT a comprehensive test. You should test your program with different data than is shown here based on the specifications given above. In the sample run below, for clarity and ease of reading, the user input is given in italics while the program output is in bold. (Note: When you actually run your program no bold or italics should appear at all. These are simply used in this description for claritys sake.) Sample Run #1 New Gear Welcome to the market! What would you like to do? 1. Buy New Gear. 2. Buy Used Gear. 3. Quit 1 How many pieces of new gear would you like to buy? 3 What would you like to do? 1. Buy New Gear. 2. Buy Used Gear. 3. Quit 3 Your total cost is 45 gold pieces. You obtained 3 pieces of new gear and 0 pieces of used gear. The cost per piece of gear is 15.00 pieces of gold. Sample Run #2 Used Gear Welcome to the market! What would you like to do? 1. Buy New Gear. 2. Buy Used Gear. 3. Quit 2 How many pieces of used gear would you like to buy? 3 What would you like to do? 3 1. Buy New Gear. 2. Buy Used Gear. 3. Quit 3 Your total cost is 15 gold pieces. You obtained 0 pieces of new gear and 3 pieces of used gear. The cost per piece of gear is 5.00 pieces of gold. Sample Run #3 Unusual Cases Welcome to the market! What would you like to do? 1. Buy New Gear. 2. Buy Used Gear. 3. Quit 5 Sorry, 5 is not a valid choice. What would you like to do? 1. Buy New Gear. 2. Buy Used Gear. 3. Quit 3 Your total cost is 0 gold pieces. You obtained 0 pieces of new gear and 0 pieces of used gear. Sample Run #4 Both New and Used Welcome to the market! What would you like to do? 1. Buy New Gear. 2. Buy Used Gear. 3. Quit 1 How many pieces of new gear would you like to buy? 3 What would you like to do? 1. Buy New Gear. 2. Buy Used Gear. 3. Quit 2 How many pieces of used gear would you like to buy? 5 What would you like to do? 4 1. Buy New Gear. 2. Buy Used Gear. 3. Quit 3 Your total cost is 70 gold pieces. You obtained 3 pieces of new gear and 5 pieces of used gear. The cost per piece of gear is 8.75 pieces of gold. Deliverables One source file pirategear.c is to be submitted over WebCourses. Restrictions Although you may use other compilers, your program must compile and run using Code::Blocks. Your program should include a header comment with the following information: your name, course number, section number, assignment title, and date. Also, make sure you include comments throughout your code describing the major steps in solving the problem. Grading Details Your programs will be graded upon the following criteria: 1) Your correctness 2) Your programming style and use of white space. Even if you have a plan and your program works perfectly, if your programming style is poor or your use of white space is poor, you could get 10% or 15% deducted from your grade. 3) Compatibility You must submit C source files that can be compiled and executed in a standard C Development Environment. If your program does not compile, you will get a sizable deduction from your grade.

*Keep this as simple as possible and work only with If-Else statements and while loops so I could have better understanding of programming. thanks

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!