Question: 1 Write a stern program that asks the user to enter a number within some range. If the user tries to joke around and input
1
Write a stern program that asks the user to enter a number within some range. If the user tries to joke around and input something incorrect, ask again, and again, and again, until they learn to get it right. Use input validation in a loop until the user enters correct input.
2
Revisit any program in a previous lab and update it to include input validation. We recommend completely re-writing the program from scratch, instead of simply copying it and inserting input validation. This speeds up the process of learning a new programming language.
3
Use a for loop to print the multiples of 10 between 1 and 100. Do this by looping 100 times and using a continue statement to skip loop iterations which are not multiples of 10.
4
Use a for loop to print the multiples of 10 between 1 and 100. Do this by looping only 10 times, perhaps by changing the update expression of the loop.
5
Rewrite the program for Gentle Jerry's Generic Goods to be even better! This time add input validation, a loop to allow the user to buy more goodies, and an option to quit buying.
6
Create a Guess the Number! game. Initialize an unsigned integer to store a random number in the range 1 -> 100 and declare another unsigned integer to store the user's guess. Ask the user for their guess. Then write a loop to keep running until the user guesses the number. If the user guesses the correct number, stop the loop and display a win message. Within the loop tell them if they are too high or too low and ask for the next guess. Finally, if the user enters 0, display the random number and stop the loop (essentially allowing them to quit the game).
7
use a loop and an array to generate a list of 10 random numbers between the ranges of 1 and 100, inclusive. Then loop through the array again and print out all the numbers.
8
String types actually contain an array of char types inside of them. You can access this array of chars by using the array subscript operator (the brackets []) on the string itself. Now that you know this, ask the user to enter a message and read it into a string variable. Then loop through the characters of the string backwards to print the message out in reverse.
9
Define an array of strings, initializing it with some names of your choice. Ask the user to specify which name they would like to search for. Next, search your array for the name the user specified, by iterating through the array and comparing their search term with each element of the array. Then let the user know if the name was found in the array or not. Finally, print out the array of strings so the user can verify.
10
Define and initialize an array of 10 random sales figures (floating point numbers). Then iterate through the array of numbers and compute the following:
11
Time to play the Lotto! Define two arrays of 5 unsigned short integers. One array is for the user's guesses and the other is for the lotto numbers. Using a for loop, randomize the five lotto numbers to be in the range: 1 -> 100. Using another for loop, ask the user for their five lotto picks. Then display the random lotto numbers to the user. To calculate the user's winnings, use a for loop and check if each element in the user's array is equal to a corresponding element in the lotto array (user[i] == lotto[i]). Increase a winnings variable by 10 for each matching number.
12
Lets modify the previous lab to improve our chances of winning. Instead of checking for a matching number in the corresponding position, we could check if a user's pick matches any of the lotto numbers. So to calculate the winnings, write a for loop to iterate through the user's five numbers, and within that loop, write a nested for loop to iterate through the five lotto numbers (NOTE: You must use different names for the loop counters. Both counters shouldnt be called i!) Increase the winnings variable by 10 for each matching number (or make the increase exponential if you want more money ).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
