Answer to Question #160222 in C++ for Rohan

Question #160222

Write a C++ program that inputs starting and ending number from the user and displays all odd numbers in the given range using while loop. 



1
Expert's answer
2021-01-31T08:01:45-0500
#include <iostream>

int main()
{
    std::cout << "Please enter two numbers: ";
    int start, end;
    std::cin >> start >> end;

        if(!std::cin || end < start)
        {
            std::cout << "Bad input\n";
            return 1;
        }

    std::cout << "Odd numbers:\n";
    
    while(start <= end)
    {
        if(start % 2 != 0)
        {
            std::cout << start << "\n";
        }

        ++start;
    }
    
    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

LATEST TUTORIALS
New on Blog