Question

Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop...

    • Uses a while loop to print the numbers from 3 - 19.
    • Uses a do-while loop to print the numbers from 42 - 56.
    • Uses a for loop to print the numbers from 87 - 95.
    • Asks the user for 2 numbers. Uses a loop to print all numbers between the given numbers, inclusive.
      • Note: Consider that your user's second number can be lower! (see example below)
      • Note: Also consider that your user might give you two of the same number.
  • Your program MUST:
    • Use a while, do-while, and for loop. The fourth loop is your choice.
    • Actively use in-line comments stating what each section of code does.
    • Use try/catch, BUT only if necessary.
    • Your program must conform to the Java coding standards
    • This is an example of what your program should output:
  • I'm going to print out the numbers 3-19 using a while loop:
    3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
    
    I'm going to print out the numbers 42-56 using a do-while loop:
    42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    
    I'm going to print out the numbers 87-95 using a for loop:
    87 88 89 90 91 92 93 94 95
    
    Now I'll print whatever numbers you'd like!
    Give me a starting number:
    2
    Give me an ending number:
    -4
    I see that your ending number is lower. Okay, I'll count down!
    2 1 0 -1 -2 -3 -4
     ----jGRASP: operation complete.

Homework Answers

Answer #1
#include<iostream>
using namespace std;

main()
{
    int i=3;
    while(i<=19)
    {
        cout<<i<<" ";
        i++;
    }
    cout<<endl;
    int j=42;
    do
    {
        cout<<j<<" ";
        j++;
    }while(j<=56);

    cout<<endl;
    for(int k=87;k<=95;k++)
        cout<<k<<" ";

    cout<<endl;
    cout<<"enter two numbers"<<endl;
    int x,y;
    cin>>x>>y;
    if(x<=y)
    {
        for(int a=x;a<=y;a++)
        cout<<a<<" ";
        cout<<endl;
    }
    else
    {
        for(int a=x;a>=y;a--)
            cout<<a<<" ";
        cout<<endl;
    }
    return 0;
}

PS:If this answer is helpful for you then please give an upvote.

Know the answer?
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
Similar Questions
8.36 Lab 8a: Count by 3 Introduction For this lab, you will use a while loop...
8.36 Lab 8a: Count by 3 Introduction For this lab, you will use a while loop to complete the task. A while loop has this basic structure: /* variable initializations */ while (/*stop condition*/){ /* statements to be performed multiple times */ /* make sure the variable that the stop condition relies on is changed inside the loop. */ } Despite the structure of the while loop being different than that of a for loop, the concept behind it is...
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
Using a for loop and range command, print the sequence of numbers from 1 to 20...
Using a for loop and range command, print the sequence of numbers from 1 to 20 (skipping two numbers for each element); that is, your code should print out the numbers 1,4, 7, 10, … (max should not exceed 20). Use x as the variable name
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while...
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with user input of 9, 5, 2, -1, then with user input of 0, -17, then with user input of 0 1 0 -1. See "How to Use zyBooks". Also note: If the submitted code has an...
Using a for Loop visual c++ Summary In this lab the completed program should print the...
Using a for Loop visual c++ Summary In this lab the completed program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. You should accomplish this using a for loop instead of a counter-controlled while loop. Instructions Write a for loop that uses the loop control variable to take on the values 0 through 10. In the body of the loop, multiply the value of the loop control variable by 2 and...
In C++ Please, In the main(), below, write a program that uses a switch-statement to choose...
In C++ Please, In the main(), below, write a program that uses a switch-statement to choose between three numbers. The number, choice, should be prompted for and each choice should print out a unique statement. Also, the prompt should continue indefinitely (i.e. keep prompting until the user force-quits the program), and there should be a general catch-all if the user enters other than the three possible choices. #include <iostream> #include <iomanip> using namespace std; int main() { <your answer goes...
Use C++ Write a program that first reads in how many whole numbers the user wants...
Use C++ Write a program that first reads in how many whole numbers the user wants to sum, then reads in that many whole numbers, and finally outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the numbers just once each and the user can enter them...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the program title and programmer’s name. Then get the user’s name, and greet the user. • Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46]. • Get and validate the user input (n). • Calculate and display all of the Fibonacci numbers up to and including the nth...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
C++ PROGRAMMING Assignment: For this assignment, you will construct a program which is capable of taking...
C++ PROGRAMMING Assignment: For this assignment, you will construct a program which is capable of taking a user-given number, and adding up all of the numbers between 1 and the given number. So if someone inputs 12, it should add 1 + 2 + 3 + 4 + … 9 + 10 + 11 + 12, and return the answer. However, you’ll be using two different methods to do this. The first method should utilize either a for loop or...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT