# Thread: Testing for truth(while statements)

1. ## Testing for truth(while statements)

Hey all, I'm a super-noob and basically I'm trying to finish off this code block for error checking and displaying multiple results from multiple checks.
Maybe that doesn't make sense what I typed but here is a run down of my code

user inputs a number and 'wants' to be told the factors of that number
what is a 'factor'
factor=division of the number inputted by another number which gives a remainder of zero
in other words
factor=(input/anumber==r0)
however, all the factors of the input must be displayed
so a test must be done for valid factors
'if factor is true, then display anumber used in factor formula'
'otherwise, if not true, then test the next number after the previously tested anumber until the input is reached, since every real/whole number has at least 2 factors (1 and the number itself)'

#include <stdio.h>

int main(void)
{
int factor=0;
int input=0;
int anumber=2;
printf("Enter a number (1-5000):");
scanf("%d",&input);
factor=(input%anumber);
if(factor>=1)
printf("The factors for %d are 1, & %d.",input,input);

else
{

while(factor==0)
{
printf(", %d",anumber);
anumber=anumber+1;
}
}
return 0;
}
I realize this is incomplete(missing loop for range test(1-5000)) but I can't quite seem to get a handle on satisfying all the problems associated with this block.

In a nutshell, I need:
all the factors from a given input on the same line
if the input is 1, to simply display, The factor for 1 is 1.
disregard all non-valid factors

I've been cracking at this all day and bupkis.

I will note it's school related, but not an assignment/homework.
Any help is appreciated.
Thank you.

Code:
```#include <stdio.h>

int main ( void )
{
int x;

printf ( "Enter a number: " );
fflush ( stdout );

if ( scanf ( "%d", &x ) == 1 ) {
int result = x / 2;
int remainder = x % 2;

printf ( "%d / 2 = %d with %d remaining.\n", x, result, remainder );
}

return 0;
}```
If (x % y) is 0 then you've found a factor. And if you can find one factor, I'm sure you can figure out how to find all factors from 1 to x.

3. Isn't using 'while(factor==0)' essentially testing for that?
I don't mean to backlash, then again the output of modulus will be the remainder, meaning I have that already.
For whatever reason since I've been at it so long, I can't see past(or recall) how to display the proper factors. More importantly the 'true-factors' or ones that past the 'while(factor==0)' loop being displayed.

I'm a beyond-noob so please, if you could simplify things bit a more, I might understand.
sorry...

4. >Isn't using 'while(factor==0)' essentially testing for that?
No. Yes, it's testing the remainder, but the loop logic is completely backward. You loop through all of your numbers and test, not the other way around:
Code:
```for n = 1 to x do
if x mod n = 0 then
print 'factor = ', n
endif
loop```

5. In that case do I want to:

while(loop!=0)