Lab 6, Part 4 ------------- This is the one about converting kg to stones and pounds. It was marked out of 3. If you did not get 3 out of 3, here's possible reasons why... a) If your had a compile-time or run-time error, you scored zero. b) Did you forget to convert the user's input from strings to numbers? Specifically, since a person's weight need not be a whole number of kg, your program should convert to float, not int: $weight_kg = (float) $_GET['weight_kg']; c) Did you get the calculation wrong? The lab sheet said: "First, convert the user's weight in kg to just pounds. Hint: A kilogram is 2.2 pounds. So if the user enters 60kg, then we have 132 pounds." So that's easy: $weight_pounds = $weight_kg * 2.2; Then the lab sheet said: "Now convert pounds to stones. Hint: A stone is 14 pounds. So if the user is 132 pounds, then s/he weighs 9.428571429 stone, which you round down to 9 stone." Also easy: $stones = (int) ($weight_pounds / 14); Lastly, the lab sheet said: "And finally separate the pounds (e.g. 132) into stones (which we worked out just now: 9 lots of 14) and the remaining pounds (6)." There are two ways to do this: $pounds = (int) ($weight_pounds - ($stones * 14)); - in which case, don't forget the (int), so that the answer is rounded down, which is what the lab sheet asked for. Or instead, you could have: $pounds = $weight_pounds % 14; The nice thing about using % is that it gives an integer, so we don't need (int). On the other hand, many students incorrectly wrote $pounds = $weight_pounds % $stones; which divides by the wrong thing. d) Did you fail to present the output as a paragraph? It needed

and

tags - because that's what the lab sheet asked for. Lab 6, Part 5 ------------- This is the one about American cash in your pocket. It was marked out of 7. If you did not get 7 out of 7, here's possible reasons why... cash.html (the form) - Did your form fail to validate? Apart from all the usual reasons (forgetting to close a div, for example), the most commons errors included the following: (a) the value of the 'for' attribute in the 'label' must match the value of the 'id' attribute in the 'input' element; (b) the values of 'id' attributes, as you know, must be unique. One of you had several
s - confusing s with
s. - Did you do a textfield for dollar notes but omit one for dollar coins? Or did you omit any others? cash.php (the program) - If your had a compile-time or run-time error, you scored zero. - Did you forget to convert the user's input from strings to ints? Or did you remember to convert but you converted to floats? - On the other hand, did you pepper the rest of your program with (int)s? They're unnecessary in this program. - Did you get the calculation wrong? Some of you forget to include the one cent coins in the final total; one or two of you forgot to include the 100-dollar bills. Some of you think that there are 10,000 cents to a ten-dollar bill (but there are only 1000). Some of you think that there are 1000 cents or 100,000 to a 100-dollar bill (but there are 10,000)! - Did you use non-meaningful names for your variables? I particularly disliked it if your variables were called $a, $b, $c, $d,... Use meaningful names! cash.css (the stylesheet) - If you did not do a stylesheet or did only a half-hearted one, you lost marks. - And if your stylesheet didn't work properly, you lost marks. General point ------------- Test your programs! Do not assume that absence of error/warning messages means your program works. Remember, you might still have logic errors. Do some examples on paper - work out what the answers should be. Then type them into your program and check that you are getting the answer you expected. Do this for a good range of examples. E.g for the cash program, I would test with a 1 cent coin and everything else zero. Then I would test with a nickel and everything else zero. Then a dime. And so on. After doing all that, I would do a test where there is one of every coin/note: the answer should be 18991 cents. And finally I'd do some tests where I have 2 of one thing and 3 of something else, or 4 of one thing, 2 of another thing and 2 of a third thing. And so on. If I get all these correct, I'd have some confidence in my program.