troubleshooting Question

Finding Divisors

Avatar of burnedfaceless
burnedfaceless asked on
5 Comments1 Solution202 ViewsLast Modified:
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.

#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;
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros