42.7k views
3 votes
Please write a C++ 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

1 Answer

4 votes

The corrected program is shown below

/*

The program outputs how many numbers are multiples of 3 and how many

numbers are multiples of 5 between the two integers (inclusive).

*/

#include <iostream>

using namespace std;

int main()

{

int number1{0};

int number2{0};

cout << " Please enter an integer: ";

cin >> number1;

cout << "Please enter another integer: ";

cin >> number2;

int count_multiple_of_3{0};

int count_multiple_of_5{0};

for(int i = number1; i <= number2; i++)

{

if(i % 3 == 0)

count_multiple_of_3++;

if(i % 5 == 0)

count_multiple_of_5++;

}

cout << "Multiples of 3: " << count_multiple_of_3 << '\\';

cout << "Multiples of 5: " << count_multiple_of_5 << '\\';

return 0;

}

So, when you run the program on run on cpp.sh, it will ask for the prompt below as well as print the others

Please enter an integer: 7

Please enter another integer: 23

Multiples of 3: 5

Multiples of 5: 3

Program ended with exit code: 0

See text below

So I have this program that is getting me crazy. Here is what it's asking me to do. The program outputs how many numbers are multiples of 3 and how many numbers are multiples of 5 between the two integers (inclusive). Now before you see what I did, I was trying to make the input 7 23 to output 5 3 and so on. Please, coders, help me out with this hot mess.

#include <iostream>

#include <iomanip>

#include <cmath>

using namespace std;

int main()

{

int number1;

int number2;

cout << "Please enter an integer: " << endl;

cin >> number1;

cout << endl;

cout << "Please enter another integer: " << endl;

cin >> number2;

cout << endl;

switch ( number1 && number2 )

{

case ( 7 == 5 && 23 == 3):

cout << number1 << " " << number2;

}

switch ( number1 && number2 )

{

case ( 893 == 29395 && 89077 == 17637 ):

cout << number1 << " " << number2;

}

switch ( number1 && number2 )

{

case ( 100 == 33 && 1 == 20 ):

cout << number1 << " " << number2;

}

return 0;

}

User Derokorian
by
8.4k points

No related questions found