Question

In: Computer Science

Cpp challenge Description The purpose of this challenge is to use the WHILE loop to control...

Cpp challenge

Description

The purpose of this challenge is to use the WHILE loop to control program flow. This challenge will use the 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 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

Solutions

Expert Solution

#include<iostream>

using namespace std;

int main(){

string txt;

int n,i;

cout<<"Enter a string to be printed: ";

cin>>txt;

cout<<"How many times to show? ";

cin>>n;

i=0;

while(i<n){

  cout<<txt<<endl;

  i++;

}

i=1;

//print 1 to 20

while(i<=20){

  cout<<i<<" ";

i++;

}

cout<<endl;

i=100;

//printing 0-100 which divisable by 10

while(i>=0){

  if(i%10==0)

    cout<<i<<" ";

  i--;

}

cout<<endl;

//reading nubmers and print *2

while(true){

  cout<<"Enter a number: ";

  cin>>n;

  if(n<0)

    break;

  cout<<n<<" * "<<"2 = "<<n*2<<endl;

  

}

//reading string until uesr gives bye

while(true){

  cout<<"Enter a string: ";

  cin>>txt;

  if(txt=="bye")

    break;

}


}

Note : If you like my answer please rate and help me it is very Imp for me


Related Solutions

Cpp challenge Description The purpose of this challenge is to use various flow control structures. This...
Cpp challenge Description The purpose of this challenge is to use various flow control structures. This challenge uses techniques for displaying formatted output, simulating a payment structure for paying off outstanding debt such as a credit card or any kind of interest-bearing loan. Requirements Declare double variables called balance, monthly, apr, apr_monthly, start_bal, interest, end_bal Declare an integer called months Prompt the user to enter values for balance, monthly, and apr Use a while loop to display the payment breakdown...
Description The purpose of this challenge is to use the IF statement to control program flow...
Description The purpose of this challenge is to use the IF statement to control program flow and to use basic arithmetic expressions. This challenge simulates a rudimentary stock chart. Requirements Take a glance at the Sample Interaction below to get an idea of how the code runs Declare a double variable called previous_price Declare a double variable called current_price Declare a string variable called symbol Declare a string variable called company Ask the user to enter a value for symbol...
Description( IN C++)!! The purpose of this challenge is to implement a stack using a Linked...
Description( IN C++)!! The purpose of this challenge is to implement a stack using a Linked List as a backing data structure Requirements Write the following structs struct Location { string name; string address; }; struct VisitNode { Location loc; VisitNode * next; }; Create a class called Stack. In this class, create a private variable VisitNode * head. This will keep track of the location of the head node. Add the following private function. This function will be used...
Description( IN C++) NO TAIL POINTERS!! The purpose of this challenge is to implement a queue...
Description( IN C++) NO TAIL POINTERS!! The purpose of this challenge is to implement a queue using a linked list as a backing data structure Requirements Write the following struct struct JobNode { string name; JobNode * next; }; Create a class called Queue. In this class, create a private variable JobNode * head. This will keep track of the location of the head node. Add the following private function. This function will be used to dynamically create new nodes...
Modify the previous program to use the Do-While Loop instead of the While Loop. This version...
Modify the previous program to use the Do-While Loop instead of the While Loop. This version of the program will ask the user if they wish to enter another name and accept a Y or N answer. Remove the "exit" requirement from before. Output: Enter the full name of a person that can serve as a reference: [user types: Bob Smith] Bob Smith is reference #1 Would you like to enter another name (Y or N)? [user types: y] Enter...
C language and it has to be a while loop or a for loop. Use simple...
C language and it has to be a while loop or a for loop. Use simple short comments to walk through your code. Use indentations to make your code visibly clear and easy to follow. Make the output display of your program visually appealing. There is 10 points deduction for not following proper submission structure. An integer n is divisible by 9 if the sum of its digits is divisible by 9. Develop a program that: Would read an input...
Java Programming - please read the description I need this description. Inside a do/ while loop...
Java Programming - please read the description I need this description. Inside a do/ while loop (while choice !='x') , create a method call that calls a switch menu with 3 cases for variable choice and X for exit application.(this is a user input) Each case calls other methods. One of those methods asks for user input float numbers to calculate addition. And the result return to another method that displays the result. Thanks for your help! Thanks for asking....
Description The purpose of this challenge is to implement a circular doubly-linked list using a dummy...
Description The purpose of this challenge is to implement a circular doubly-linked list using a dummy node. This challenge simulates an operating system’s window manager. Requirements Write the following struct struct Window { string appname; Window *next; Window *prev; }; Create a class called WindowManager. In this class, create a private variable Window * head. This will keep track of the location of the head node. Create private variables Window * current, * dummy. current will keep track of the...
This is for C++ You must use either a FOR, WHILE, or DO-WHILE loop in your...
This is for C++ You must use either a FOR, WHILE, or DO-WHILE loop in your solution for this problem. Write a quick main console program to output the following checker pattern to the console: #_#_#_#_# _#_#_#_#_ #_#_#_#_# _#_#_#_#_ #_#_#_#_#
Re-write following while loop into Java statements that use a Do-while loop. Your final code should...
Re-write following while loop into Java statements that use a Do-while loop. Your final code should result in the same output as the original code below. int total = 0; while(total<100) { System.out.println("you can still buy for"+(100-total)+"Dollars"); total=total+5; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT