Answer to Question #174144 in C++ for Eadoni

Question #174144

Write a program that uses while loops to perform the following steps: a. prompt the user to input two integers: firstNum and secondNumb. Output all odd numbers between firstNum and secondNum inclusive.

1
Expert's answer
2021-03-22T06:40:12-0400
#include <iostream>
using namespace std;


int main()
{
    //a. Prompt the user to input two integers: firstNum and secondNum
    //(firstNum must be less than secondNum).
    cout << " Prompt the user to input two integers. First must be less than second\n";
    double firstNum = 2;
    double secondNum = 1;


    while (firstNum > secondNum)
    {
       cout << "enter first number: \n";
       cin >> firstNum;
       cout << "enter second number (must be more than first number): \n";
       cin >> secondNum;


       if (firstNum > secondNum)
           cout << "first number must be less than second number. Try again. \n";
    }
    cout << "\n";


    //b. Output all odd numbers between firstNum and secondNum.
    cout << "a.Output all odd numbers between firstNum and secondNum.\n";
    int number = firstNum;


    while (number <= secondNum)
    {
        if (number % 2)
            cout << number++ << "\n";
        else
        {
            number++;
            continue;
        }
    }
    cout<<"\n";

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS