Question

Answer each of the following questions about loops in C++. In each question, LABEL the three...

Answer each of the following questions about loops in C++. In each question, LABEL the three parts of the loop.

a.) Write a while statement that will ask the user for integers until the user enters the sentinel value of -1. Declare all needed variables.

b.) Write a for statement that will print out all the multiples of 3 between 1 and 200. Declare any needed variables.

c.) Write a do while loop that will ask the user for characters and end when the character is equal to 'e'. Declare any needed variables.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//if you have any query then comment below.please rate the answer

#include <iostream>

using namespace std;
int main()
{
int n;
while(1)
{
cout<<"Enter integer: ";
cin>>n;
if(n==-1)
break;
}

}

nter integer 2 Enter integer: 3 Enter integer: 4 nter integer:5 nter integer:-1 Process returned 0 〈0x0〉 execution time : 5.5

#include <iostream>

using namespace std;
int main()
{
int n;
for(int i=1;i<=200;i++)
{
if(i%3==0)
cout<<i<<" ";
}

}

6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 75 78 818 50 153 156 159 162 165 168 171 174 177 180 183 1

#include <iostream>

using namespace std;
int main()
{
char ch;
do
{
cout<<"Enter character: ";
cin>>ch;
}while(ch!='e');

}

Enter character: a Enter character: Enter character: c Enter character: d Enter character: y Enter character: rocess returned

Add a comment
Know the answer?
Add Answer to:
Answer each of the following questions about loops in C++. In each question, LABEL the three...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Answer using programming in C only. 6 pts Use a while loop to complete the following:...

    Answer using programming in C only. 6 pts Use a while loop to complete the following: Prompt the user to enter integers one by one, until the user enters a negative number to stop Calculate the sum and the average of all the numbers entered by the user Print the sum and the average onto the screen after the loop. Declare and initialize all variables. Be sure to keep a count of the numbers entered for the average calculation

  • Create three variables for an int array, the size of the array, and a Scanner object...

    Create three variables for an int array, the size of the array, and a Scanner object to read keyboard input. Ask the user to specify the size of the array and then construct an int array of that size. Next, use a for loop to continuously ask the user to specify values for each location in the array. Lastly, print contents of the array as a histogram using the asterisk character (*). This will require using nested for loops. The...

  • C++ please 27.5 Loops (nested)**: Sum a given number of integers A user will enter an...

    C++ please 27.5 Loops (nested)**: Sum a given number of integers A user will enter an initial number, followed by that number of integers. Output those integers' sum. Repeat until the initial number is O or negative. Ex: If the user enters 3 96 1 0, the output is 16 Ex: If the user enters 396125 3 0, the output is 16 Hints: Use a while loop as an outer loop. Get the user's initial number of ints before the...

  • In Python Exercise – For & While Loops Create a new file called loops.py and use...

    In Python Exercise – For & While Loops Create a new file called loops.py and use it for all parts of this exercise. Remember the difference between input and raw input? Be sure to test your code for each part before moving on to the next part. Write a program using a for loop that calculates exponentials. Your program should ask the user for a base base and an exponent exp, and calculate baseexp. Write a program using a while...

  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

  • Write a program that allows the user to enter a series of exam scores. The number...

    Write a program that allows the user to enter a series of exam scores. The number of scores the user can enter is not fixed; they can enter any number of scores they want. The exam scores can be either integers or floats. Then, once the user has entered all the scores they want, your program will calculate and print the average of those scores. After printing the average, the program should terminate. You need to use a while loop...

  • Using c++ ) You will write a program that will do the following: prompt the user...

    Using c++ ) You will write a program that will do the following: prompt the user enter characters from the keyboard you will read the characters until reading the letter O' You will compute statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character ' Example inpu mJ0*5/tx1@3qcx0 The 'Q'should be included when computing the statistics properties of the input. Since characters are...

  • Please code in c 1. Write a program which does the following: Declare and initialize three...

    Please code in c 1. Write a program which does the following: Declare and initialize three pointers. One points to an integer, one points to a float and one points to a character variable Ask the user to enter appropriate values for these variables. Output the values to the screen by accessing the variables directly and then by using pointer references. Print the address of each variable. Modify the variables by performing any arithmetic operation only using pointer refer- ences...

  • (5 Marks) 3 Write a C sentinel-controlled while loop that will compute the sum of integers...

    (5 Marks) 3 Write a C sentinel-controlled while loop that will compute the sum of integers entered by the user ending with 999. Include all declaration and initialization of variables. Also, output the sum.

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT