Answer to Question #177874 in C++ for simisola oluwaseyitan alabi

Question #177874

Write a program that prompts the user to enter two integers. The program outputs how many numbers are multiples of 3 and how many numbers are multiples of 5 between the two integers (inclusive).


1
Expert's answer
2021-04-02T16:14:41-0400
#include <iostream>

int main()
{
    std::cout << "Please enter two integers: ";
    int first, second;
    std::cin >> first >> second;

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

    int counter3 = 0;
    int counter5 = 0;
    
    for(int i = first; i <= second; ++i)
    {
        if(i % 3 == 0)
        {
            ++counter3;
        }

        if(i % 5 == 0)
        {
            ++counter5;
        }
    }
    
    std::cout << "The number of multiples of 3 is " << counter3 << "\n";
    std::cout << "The number of multiples of 5 is " << counter5 << "\n";
    
    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
APPROVED BY CLIENTS