Output all the odd numbers between firstNum and secondNum inclusive.
#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;
}
Comments
Leave a comment