# Need help with the logic of the program

• 01-14-2002
unregistered
Need help with the logic of the program
I need logic to the following program:
The input is like
2, 3.4, 5, 2.2, 4.6, 5.7, 3.6 .....
The output should be sorted out as:

0-2 :1
2-4: 3
4-6: 3
6-8: 0

The numbers are checked if they are in a particular range and the counter is increased accordingly.
How can this be implemented?I need some help with the logic.
• 01-14-2002
Shiro
You can use the if-construction. This construction is:

Code:

```if (condition) {     /* the code here will be executed */ } else {     /* the code here will be executed */ }```
You could use this construction like this:

Code:

```if (number > 2 && number < 4) {     .. } else if (number >= 4 && number < 6) {     ... } etc.```
• 01-14-2002
Unregistered
Hi,
Thanks, I tried this method and it works but I need some other method because the if-else method is too lengthy and if I have the range set to
0-1:
1-2:
2-3:
3-4: and so on then there are so many if statements to be used so I was thinking of some other method. If there is some other way to do it please let me know.
• 01-14-2002
Uraldor
try something like:

double input;
int numbers[RANGE];
cin >> input;
int value = (int)floor(input);
numbers[value]++;

then after you've inputted all the values

for(int i = 0; i < RANGE; i++)
{
cout << i << " - " << i + 1 << " : " << numbers[i] + numbers[i+1] << endl;
i++; // incremet again
}

this hasn't been compiled,it's intended to give you an idea. if you still have problems.. post again.

U.
• 01-14-2002
frenchfry164
the value declaration looks weird, plz explain it to me. Just curious. That int thing in parentesis looks like typecasting, but why would you typecast an int with an int?
• 01-14-2002
Uraldor
look at the floor() function, you'll figure it out.

hint: what does floor() return??
• 01-16-2002
Unregistered
Thanks Uraldor

After making some changes the program worked fine.Thanks for the logic.