Answer to Question #275451 in C++ for mot

Question #275451

Output all the odd numbers between firstNum and secondNum inclusive.


1
Expert's answer
2021-12-04T10:19:08-0500
#include <iostream>
using namespace std;




int main()
{
    
    
    double firstNum = 2;
    double secondNum = 1;
    while (firstNum > secondNum)
    {
       cout << "Enter first number: ";
       cin >> firstNum;
       cout << "Enter second number (must be more than first number): ";
       cin >> secondNum;
	   if (firstNum > secondNum){
	       cout << "First number must be less than second number. Try again. \n";
	   }
       
    }
    cout << "\nAll odd numbers between first number and second number:\n";
    int number = firstNum;
	while (number <= secondNum)
    {
        if (number % 2!=0){
            cout << number<< "\n";
		}
		number++;
    }
	cin>>number;
	return 0;
}

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