Each solution explains what is happening and why something is being done in the comments.
6.1) Write a program which asks the user for 10 numbers. The total of the 10 numbers should be shown after the last one has been entered. Each number which is entered must be between 1 and 10, and your program should enforce this. (Hint: Use a For...Next loop to get the 10 numbers, use the validation code presented earlier in this chapter and keep a running total - one which the new values are added to as they are entered). (Solution)
6.2) Extend the program you wrote in exercise 6.1 so that, instead of asking for a specific number of values from the user, it continues to ask for numbers until the user enters -1. The value of -1 should not be counted in the total. (Solution)
6.3) Write a program which will display every combination of foreground and background colors in a 16 x 16 grid. (Hint: use two nested For...Next loops.).
6.4) Update the program you wrote in exercise 4.3 so that it asks the user for the length, width and height of the room. You should read these in as floats and remember to check for invalid data (hint: in this case, you cannot have negative values for dimensions). (Solution)
6.5) Write a program which asks the user for a width and height, for a rectangle which will be drawn on the screen - you should make sure the width and height that the user enters is valid. The program should then draw a rectangle in the centre of the screen, using a character entered by the user. For now, you do not need to think about the possibility that the user may enter more than one character for the string. (Hint: the size of a console is typically 80 characters wide by 25 high.) (Solution)
6.6) Extend the program you wrote in exercise 6.5 so that instead of using a character to draw the rectangle, it draws it in a block of color. (Hint: use the background color.) (Solution)
| Previous topic | Chapter contents | Next topic |
|---|---|---|
| Summary | User Guide contents | None |