I have this assignment and I got most of the program but I cant seem to make the counter work right what am I doing wrong?

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
	int num1, num2, number;
	cout << "Please enter an integer: ";
	cin >> num1;

	cin.ignore();
	cout << "Please enter another integer: ";
	cin >> num2;

	
	for (int counter = 0; counter <= number; counter++)
	{
		int number = num2 % 2; (number % 2 && number >= counter);
		cout << "The amount of even numbers between " << num1 << " and " << num2 << " is " << number;
		break;

	}
	cout << endl;

}

Sit back an analyze what you're trying to do.

It looks like your assignment is to count how many even numbers occur between num1 and num2. Is that count to also include num1 and/or num2 if they are even?

num1 and num2 should be the starting and ending points of the for loop. You need a separate loop variable to increment through the loop. Counter must be separate, and set to 0; it gets incremented when the loop variable is divisible by 2.

Your summary output must be after the loop concludes.

Read the error messages your compiler is issuing, fix those things. Right now, I don't believe your code even compiles, much less does so cleanly.

Ok....It compiles...its just doesnt give me the answer I want...Ima try what you said and see what happens.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.