int main()
{
int n;
int num;
cout << "what is the number";
cin >> num;
int divs [10];
for(n=0;n<10;n++)
{
divs[n]=num / n;
}
for(n=0;n>num;n++)
{
if (divs[n]== a interger)
{
cout << divs[n];
}
}
return 0;
}
this is what I have for a program that prints factors of a number out. if (divs[n] == a intiger) is obvisly not a valid condition do any of yall know a funtion to test for that? I saw someone recomend the ctype header but I dont think any of those function would check for this if so please tell me
You can check if somethign is an int or a float by seeing what you made it.
1 2
int x; //this one is an int
float y; // this one is a float
A ha ha.
Anyway, this:
num / n;
will ALWAYS be an int, because an int divided by an int gives you an int. If you want to allow non-integer results, make one of them a float at the time of division.
Given two int values to divide, an easy way to check for an int answer is:
1 2 3 4
if (a % b == 0)
{
// the answer is an int
}
If that's not an option, you have to decide what counts as an int.
If you want to start looking at floating point values and deciding if they're integers, you need to understand what a floating point number is: http://floating-point-gui.de/
i read web page on floats mos and yeah i didnt know that about floats however still dont know how to fix my problem. right now i took the first loop out and used module on num%n and i go float exception error after that changed all varibles to floats but that didnt work either.