Loops 2

Description

The purpose of this challenge is to use the DO-WHILE loop to control program flow. This challenge will use the DO-WHILE loop in various ways.

Requirements

Write all your code for the following steps in one file.

  1. Ask the user to enter a single string. Ask the user to enter an integer value for a variable called repetitions. Use a while loop to display this string (of your choice) repeated repetitions times, one string per line
  2. Use a while loop to count and display all the integers from 1 to 20. Separate numbers with a space
  3. Use a while loop to display all numbers divisible by 10 starting from 100 down to 0. Only show numbers divisible by 10. Separate numbers with a tab. TAB character is displayed using the \t escape sequence. (Remember that \n is a newline; use similarly)
  4. Use a while loop to keep asking the user for an integer as long as positive numbers are being entered. For every positive number entered, show its value multiplied by 2. Once a negative number is entered stop asking and quit the loop
  5. Use a while loop to keep asking for a string until a particular string is entered (for example, “bye”)

Do Not Use

You must use the DO-WHILE statement. You may not use any other looping mechanism.

Sample Interaction / Output

Enter a string to be repeated: coffee
How many times to show? 5

coffee
coffee
coffee
coffee
coffee
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

100  90   80   70   60   50   40   30   20   10 

Enter a number: 3
3 x 2 = 6
Enter a number: 7
7 x 2 = 14
Enter a number: -2

Enter a string: yo
Enter a string: hi
Enter a string: hola
Enter a string: sup
Enter a string: bye

LEGEND
PROGRAM OUTPUT
USER ENTRY
FROM INPUT

CATALOG ID: CPP-LOOP0002

Print Requirements