In the code below it is not registering float values - for example if it divides 4 by 3 it is registering 1 as an answer (if you enter 4 when it loops up to 3 it doesn't record the float value).

I want to store the float value so I can see if it is a divisor or not.

I want to store the float value so I can see if it is a divisor or not.

```
#include <iostream>
#include <cmath>
bool is_integer(float number) {
return std::floor(number) == number;
}
int divisors(int number) {
int i = 1;
float result;
for (i = 1; i<= number; i++) {
result = number / i;
std::cout << i;
std::cout << result;
std::cout << "\n";
}
}
int main()
{
int counter = 1;
int number;
int number_divisors;
std::cout << "Enter a number to find the divisors";
std::cin >> number;
number_divisors = divisors(number);
return 0;
}
```

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get this solution by purchasing an Individual license!
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

```
for k = 2 to sqrt(testnumber)
if [testnumber mod k) == 0] {
print (k, "is a factor of", testnumber)
print (testnumber/k, "is a factor of", testnumber)
}
next k
```

result = number / i;you could make it 2 statements as suggested by phoffric or do

```
result = ((float)number )/ i;
```

this would 'cast' the nominator to float and the division result is float as well.

Sara

```
number_divisors = divisors(number);
```

you seem to be expecting divisors() to return something but I don't see a return statement in the function.

```
float result;
for (i = 1; i<= number; i++) {
result = number / i;
std::cout << i;
std::cout << result;
std::cout << "\n";
}
}
```

also if you are trying to count divisors the logic you've used is not going to do any counting..... for that you have to do what Dr.Klahn has suggested

if you are trying to count divisors the logic you've used is not going to do any counting

you could make your code work correct like with the following:

```
int divisors(int number) {
int i = 1;
float result;
int count = 0;
for (i = 2; i<= number/i; i++) {
result = ((float)number) / i;
if ((number/i)*i == number) {
count++;
std::cout << i " is divisor of " << number << std::endl;
}
std::cout << i << " " << result << std::endl;
}
return count;
}
```

Sara

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
C++

From novice to tech pro — start learning today.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get this solution by purchasing an Individual license!
Start your 7-day free trial.

Try using f instead of number when calculating result.