Be sure you have read (or at least skimmed) the assigned readings from chapter 5.
Please include with each part of the assignment the Honor Code pledge or just the word ``pledged'', plus one or more of the following about collaboration and help (as many as apply).1Text in italics is explanatory or something for you to fill in. For written assignments, it should go right after your name and the assignment number; for programming assignments, it should go in comments at the start of your program(s).
Do the following programming problems. You will end up with at least one code file per problem. Submit your program source (and any other needed files) by sending mail to bmassing@cs.trinity.edu with each file as an attachment. Please use a subject line that mentions the course and the assignment (e.g., ``csci 1312 hw 3'' or ``CS1 hw 3''). You can develop your programs on any system that provides the needed functionality, but I will test them on one of the department's Linux machines, so you should probably make sure they work in that environment before turning them in.
Some words about checking for non-numeric input: Doing a great job of ``validating input'' is probably outside the scope of this course -- it turns out to be not an easy problem to solve in C -- so in the programs you write for homework, generally speaking what I have in mind is for you to just check the return value from scanf, as I do in the examples in class, and bail out of the program if it indicates an error. You may be tempted to make your program prompt the user again, but don't do that either -- it breaks my semi-automated testing and again is not trivial to do in C. Just checking the return value from scanf is far from perfect but at least ensures that the variable(s) read from standard input have sensible values, which is good enough for our purposes right now. Note that if the problem doesn't make sense for some inputs (e.g., ``counting change'' for a negative number) I'll usually also ask that you reject such input (with an error message).
Write a C program that prompts the user for the number of caps and prints the corresponding price. Of course(?), the program should print an error message and stop if input is not numeric or numeric but less than 0. The program should also print an informational message if the price would be the same for a larger number of caps (i.e., the number entered is less than the ``minimum'' order, or not a multiple of 5). It should also print a message if the order qualifies for the volume discount.
Some sample executions ([prompt] is the usual prompt,
usually your user name plus machine name, etc.)
[prompt]$ ./a.out how many caps? 45 price $100 you could get 50 caps for the same price [prompt]$ ./a.out how many caps? 80 price $130 [prompt]$ ./a.out how many caps? 82 price $135 you could get 85 caps for the same price [prompt]$ ./a.out how many caps? 101 price $155 you could get 105 caps for the same price [prompt]$ ./a.out how many caps? 200 price $250 [prompt]$ ./a.out how many caps? 202 you qualify for the volume discount! price $254 you could get 205 caps for the same price [prompt]$ ./a.out how many caps? don't know invalid input (not integer) [prompt]$ /a.out how many caps? -12 invalid input (not positive) [prompt]$ ./a.out how many caps? 0 invalid input (not positive)