I need help with an assignment I am working on. Here is the assignment:
count all the even numbers between X and Y, where X and Y are entered by the user. Do not include X and Y.
EXAMPLE 1:
Please enter an integer: 0
Please enter another integer: 10
The number of even numbers between 0 and 10 is 4
EXAMPLE 2:
Please enter an integer: 10
Please enter another integer: 0
The number of even numbers between 10 and 0 is 4
Note that the numbers can be entered in any order (that is, the lower one does not have to come first).
I have it just about finished but it is not working properly. Each time I run it, I don't get 4, it keeps changing. I know it's gotta be something small that I am missing, but could you help me. Here is what I have:
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int min, max, number = 0;
unsigned seed = (unsigned long) (time(NULL));
srand(seed);
cout << "Please enter an integer: ";
cin >> min;
cin.ignore();
cout << "Please enter another integer: ";
cin >> max;
int range = max - min + 1;
for (int counter = 0; counter <= number; counter++)
{
int number = rand()/100%range + min;
cout << "The number of even numbers between " << min << " and " << max
<< " is " << number;
break;
}
cout << endl;
}
What is wrong with this program that the number printed keeps changing?