CS 215 – Spring 2017 Lab 4 – Counting Game Learning Objectives: - Use of while loops and basic loop strategies for solving problems General Description: Write a “Counting Game” where the user enters the start number, count by (increment) and start number for counting. Once the parameters are entered, the program prints the count on the screen on one line, along with the average of the numbers printed on the next line. - The start number may be any number the user wants. The county-by number should be 1 or above. If the user enters an invalid number, the question should be repeated until the user enters a correct answer. The end number should be at least start+CountBy, to ensure there will be at least two numbers in the count. For instance, if the start is 5 and count-by is 2, the end must be 7 or greater. Again, when the user enters an invalid number, repeat the question. Finally, the program asks the user if they want to play again. If the user enters yes, repeat the entire process. Otherwise, end the program with system pause as usual. You may assume the user will enter only integer values. See next page for a sample execution Sample Run: (sample user input in blue) The Counting Game! Where should we START counting? 5 What should we COUNT BY? -1 Sorry, please enter a number 1 or greater. What should we COUNT BY? 3 Where should we STOP counting? 7 Sorry, please enter a number 8 or greater. Where should we STOP counting? 14 Counting! 5 8 11 14 Average is: 9.5 Play Again? (yes/no) yes The Counting Game! Where should we START counting? 1 What should we COUNT BY? 1 Where should we STOP counting? 4 Counting! 1 2 3 4 Average is: 5 Play Again? (yes/no) elephant Press any key to continue...
© Copyright 2026 Paperzz