Question

C++ beginners coding: Nested loop, Do-While Code for problem: Until the user wants to quit (by...

C++ beginners coding:

Nested loop, Do-While

Code for problem: Until the user wants to quit (by typing "q" or "Q") assume there is a # (assuming it's positive), print all multiple of 3 from 3 to their #. The user should be asked to quit only after one run of the program.

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

Solution:

Code:

//Include necessary headers #include <iostream> using namespace std; //Main method int main() /*Declare necessary variables*/cin>>sentinal; //Loop condition while( sentinal!=q && sentinal!=0);

Output:

2./main Enter the positive value: 5 Values are: Do you want to continue (0/9):n Enter the positive value:9 Values are: 9 Do y

Copyable Code:

//Include necessary headers

#include <iostream>

using namespace std;

//Main method

int main()

{

/*Declare necessary variables*/

int number,val;

char sentinal;

/*Nested do...while loop*/

do

{

/*Prompt and get input*/

cout<<"Enter the positive value:";

cin>>number;

//Print statement

cout<<"Values are:\n";

int i=1;

/*Do...while loop*/

do

{

//Calculation

val=i*3;

//Condition

if(val<=number)

{

//Print the result

cout<<val<<endl;

}

i++;

}

//Condition for the loop

while(val<number);

/*Prompt and get for quit*/

cout<<"Do you want to continue(Q/q):";

cin>>sentinal;

}

//Loop condition

while(sentinal!='q' && sentinal!='Q');

}

Add a comment
Know the answer?
Add Answer to:
C++ beginners coding: Nested loop, Do-While Code for problem: Until the user wants to quit (by...
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
  • Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program...

    Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program will calculate and display the total of all numbers up to a specific number (entered by the user). Only positive numbers are allowed. Part B: User-controlled loop Part A Input Validation loop Part A: Summation loop Examples: When 5 is entered the program will calculate the total as 1+2+...+5 and display 15. When 2 is enterered the program will calculate the total as 1+2...

  • Write a perl program Use a while loop to get user input until the user enters...

    Write a perl program Use a while loop to get user input until the user enters "quit" Use a regex to replace any occurrence of the word "python" with the word "perl" and print out the updated version Provide the perl program (.pl file) as well as a screenshot of the output (show at least one example with python being replaced)

  • Objectives: Use the while loop in a program Use the do-while loop in a second program...

    Objectives: Use the while loop in a program Use the do-while loop in a second program Use the for loop in a third program Instructions: Part A. Code a for loop to print the Celsius temperatures for Fahrenheit temperatures 25 to 125. C = 5/9(F – 32).Output should be in a table format: Fahrenheit Celsius 25 ? . . . . . . . . Turn in the source and the output from Part A. Part B. Code a while...

  • For this assignment, you will apply what you learned in analyzing for, while, and do-while loops...

    For this assignment, you will apply what you learned in analyzing for, while, and do-while loops by writing these statements yourself. The Java™ program you write should do the following: Display a pyramid of asterisks onscreen (i.e., a nested for loop) Display the integers 10 to 1 in decreasing order, one number per line (i.e., a while/do-whlie loop) Add 7 until the sum becomes greater than 157, at which point the program should display both the sum and the number...

  • This question deals with extending already existing Java code via a while loop. Ask the user...

    This question deals with extending already existing Java code via a while loop. Ask the user how many year inputs he wants to check - an integer. Assume that the user always gives an input which is between 1 and 5 (inclusive). Next, ask the user for K number of year inputs where K = the number user has given as input before (inside a while loop). Check for each year input whether that year is a leap year or...

  • The purpose of this assignment is to get experience with an array, do while loop and...

    The purpose of this assignment is to get experience with an array, do while loop and read and write file operations. Your goal is to create a program that reads the exam.txt file with 10 scores. After that, the user can select from a 4 choice menu that handles the user’s choices as described in the details below. The program should display the menu until the user selects the menu option quit. The project requirements: It is an important part...

  • (java) Write a While loop that prompts the user for only even numbers. Keep prompting the...

    (java) Write a While loop that prompts the user for only even numbers. Keep prompting the user to enter even numbers until the user enters an odd number. After the loop ends, print the sum of the numbers. Do not include that last odd number. You should not store the numbers in an array, just keep track of the sum. Make sure to use a break statement in your code. You may assume that a java.util.Scanner object named input has...

  • 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...

  • For this lab, modify the python code below so it will continuously be asking user for...

    For this lab, modify the python code below so it will continuously be asking user for inputs to calculate the interest earned until the user enters number 0 (zero) in principle. Once the user enters any number less or equal to 0 in principle, the program will end. here is my code: # Programming Exercise 3-14 # Local variables p = 0.0 r = 0.0 n = 0.0 t = 0.0 loop = True while loop: p = float(input('\nEnter the...

  • In this exercise, write a complete Java program that reads integer numbers from the user until...

    In this exercise, write a complete Java program that reads integer numbers from the user until a negative value is entered. It should then output the average of the numbers, not including the negative number. If no non-negative values are entered, the program should issue an error message. You are required to use a do-while loop to solve this problem. Solutions that do not use a do-while loop will be given a zero. Make sure to add appropriate comments to...

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