even numbers

Write a program that calculates the product of even natural numbers in a given range [n1, n2] - n1 and n2 to enter.
Hint: if an even value is entered for n1, the cycle starts from n = n1, if an odd value is entered - from n = n1 + 1

I need a little help for this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;

int main(){
	
	int n, num1,num2;
	cout<<" Enter first number: "<<endl;
	cin>> num1;
	
	cout<<" Enter second number: "<<endl;
	cin>>num2;
	
	if (num1 %2==0){
		cout<<"Your two numbers multiplied equals: " << (num1 *= num2) << endl;
	}
	
	else{
		cout<<"Your numbers multiplied equals: "<< ((n+1)*num2)<<endl;
	}
	
	
	
	
}
Start by simply ouputting every number from n1 to n2.
First let's figure out how to get and printout all the even numbers between the two user inputs:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>

int main()
{
	std::cout << "Enter the starting number: ";
	int start_num { };
	std::cin >> start_num;

	std::cout << "Enter the ending number: ";
	int end_num { };
	std::cin >> end_num;
	std::cout << '\n';

	std::cout << "List of even numbers between " << start_num << " and " << end_num << '\n';

	// if the starting number is not even bias it towards even
	if (start_num % 2) { start_num++; }

	for (int i { start_num }; i <= end_num; i += 2)
	{
		std::cout << i << ' ';

		// use the same loop to calculate the product summation
	}
	std::cout << '\n';
}
Topic archived. No new replies allowed.