CSE/ENGR 142 Homework 2

Detailed Instructions

Due: web submission by Friday, July 9th at 5:00 p.m. sharp, paper receipt submission by 10:00 p.m.


Being typical college students, you and your friends order a lot of pizza. You eat so much, in fact, that your parents send you $20 every Friday to buy a pizza for you and your friends. However $20 is not always enough; sometimes you accidentally order the expensive toppings and have to pay for the extra yourself. Since you're completely broke, you've decided to write a program that will help you prevent spending any of your hard earned money. You've decided it will be most helpful if the program asks for the size of the pizza, then three toppings of your choice (you never eat more than three toppings), and tells you what the pizza costs at each step of the way. If at any point you've spent more than $20, the program will tell you, and you can stop getting toppings.


Overview

In this homework, you'll need to use conditionals and simple functions. You'll have plenty of help along the way, including a sample executable you can run to see how the finished product should work. Read all of the information on this page before starting. Pay particular attention to the specifications below, and, when you think you're done, be sure to double-check them before you submit your code.

Program Specifications

The program will run through the steps of ordering a pizza. It starts with the knowledge that you have $20, and figures out how close you're coming to that amount as you fill your order. It will go through the following steps:

  1. Prompt the user for the size of the pizza (small, medium, large).
  2. Prompt the user to choose a topping  (extra cheese, pepperoni, olives, anchovies, or no topping).
  3. Prompt the user for a second topping.
  4. Prompt the user for a third topping.

At each of the above steps, the program should do the following:

  1. Calculate the new price of the pizza.
  2. Output the following:

    Step 2 is going to behave the same way every time you do it, thus it's an ideal candidate for a function. We've written the skeleton of a function called checkPrice, which you will be required to use to implement this step. You must fill in the body of the function so you can make calls from main to that function. More details are below..

You always order your pizza from Fat Tony's (they've got the best pizza in town, and free delivery), so the prices for the pizza and toppings never change. (Big Hint: these prices would be good things to #define) Here are the prices:

Pizza Size
Small - $12.00
Medium - $15.00
Large - $16.50

Toppings
Extra Cheese - $1.50
Pepperoni -      $1.00
Olives -            $2.00
Anchovies -      $1.50

Implementation Requirements

For the most part, you are free to implement your program as you wish.  However, there are a few specific requirements that must be met.

           /* Prints out the status of your pizza's price
            *
            * Parameters passed in to the function:    pizzaPrice - a double containing the price of the pizza
            * Value returned by the function: none
            *
            * This function prints out the following:
            *   1) The current price of the pizza
            *   2) If the price is LESS than your alloted funds, how much more you can spend.
            *   3) If the price is MORE than your alloted funds, how much of your own money you must spend.
            */

            void checkPrice(double pizzaPrice)
      {
      }

You are free to use additional functions if appropriate.  If you find that you are writing the same code over and over, that might suggest creating a function and calling it as needed.  But you are only required to implement the single function described above.

Sample Executable

Download and run the sample PC executable hw2.exe and run it several times with different inputs until you get the general idea of how it works. One technique for running it is to double-click on it from Windows Explorer.

If you play with the sample executable very long, you'll notice that it doesn't handle errors very well. For example, inputting a character instead of an integer causes weird things to happen. Don't worry about these problems for now.  We'll learn how to fix problems like these later in the course.

Getting Started

It would be possible to type in your program from scratch. In that case, you would unfortunately have to go through some additional steps to create a project and a workspace.  To make it easier, just modify hw2.c, the source file provided in the self-extracting archive (get the version 6 archive if you are using MSVC 6.0, or the version 5 archive if using MSVC 5.x).  Just as in the last homework, download the archive to a floppy disk. Once you have extracted the files, run MSVC from the Start menu and open the file hw2.dsw using the File menu's Open Workspace... option. Use the MSVC editor to modify hw2.c. Be sure to re-save hw2.c on your floppy, because you will need it later.   You can also get the file hw2.c by itself but in this case you will have to build a project and a workspace to compile it in.

Once you've added some code to your program, you may find that it doesn't compile right away. Each of these compilation or "syntax" errors has to be solved. Notice that if you click on the error message, you will be placed in the editing window at a point near where the error was detected (often the actual error is a little earlier). Each time you make a change to the program, don't forget to recompile it before executing again.

You will find that the best way to proceed is not to type in the entire program at once and then try to compile. A better way would be to break the problem up into smaller parts, getting each part to build and work properly before moving on to the next.

IMPORTANT NOTE: This work must be entirely your own. If you are in doubt about what is and is not acceptable, please re-read the relevant section from the syllabus .
 

Submitting Your Work

Just as in Homework 1, you will be submitting your C file via the web and submitting your receipt on paper.

After you're finished testing your program and rereading the instructions, go to the turn-in page to submit your C file. Fill out the form (click on the links labeled "help" if you don't understand something). At the bottom of the form, you will need to specify the name of your file, which is probably named something like A:\hw2.c, but you can use the Browse button to find it if you like. Click the turn in button at the bottom when you're done. Your program will be checked to be sure that it compiles. If all is well, you'll get a receipt back showing what we received. Print out and hand in this receipt at the CSE 142 Homework Turn-In Box. You won't get credit for the assignment if you don't turn in this receipt.

You may turn in the program as many times as you wish.  Only the last version is graded, and only the receipt from this last version should be handed in.


Back to main Homework 2 page...