can someone give me some questions on loops?

i need to practice "while loop" and "for loop". can someone give me around 10-15 questions? please do not give a lot complex questions.
Last edited on
OK, try these:

While-loops:

1. Write a loop to ask the user to guess a number from between 1 and 100. Generate the number to guess randomly.

2. Write a loop to read a line of text from a file until there are no more lines of text. Display each line read on the screen.

3. Write a loop that handles four choices from a menu: 1, 2, 3, and 'q'. Write a function for each number selected (function1, function2, function3) and exit the loop when the user choose 'q'.

For-loops:

4. Write a loop to input five strings entered by the user into either a character array or better yet, a vector.

5. Write another loop to display each string from question 4.

6. Write a loop to reverse the characters in a string entered by the user.

Make a mastermind game.

Create 4 variables that represent 4 colors.
randomize the order of these colors.
Using loops, do the following
ask the user to input a guess.
check the users guesses
display how many are correct (if you wish you can display which are right / wrong)
Keep looping until the player gets it right.

That'll take you a good afternoon. :)
Topic archived. No new replies allowed.