USING LOOPS ‘for” and ‘do…while’
Have and input of some number between 1 and 10000
Check
to see if it is valid input, if not ask for the number to be entered again.
Print out a factor list for the number.
Sample run…
Please enter a number (1-10000) 12000 SORRY
12000 IS NOT VALID, ENTER AGAIN! Please enter a number (1-10000) 144 Number: 144 Factors: 1, 2, 3, 4, 6, 8, 9, 12, 16, 18, 24, 36, 48,
71, 144 Number of factors: 15
Hints: for the bad input, use a do…while loop
do{
cout<<”Please enter a number (1-10000)”<<endl;
cin>>num;
if (num > 10000 || num < 1) {
cout<<”sorry…”<<endl;
delay a bit then clear screen.
}while (num > 10000 || num < 1);
for finding factors…
Inside a for (x=1; x<=num; x++)
Check if division by number results in no remainder. If it does, it is a factor. Keep a count.
If (num%x ==0)
{
count++;
cout<<x;
}
There is a
fine difference of perspective between getting
involved and being committed. In ham and
eggs, the chicken is involved, but the pig is committed. John A.
Price
