Can you tell me why my loop is not working correctly. I am attempting to have only the groups (20-30),(490-500),and (8120-8130) printed on the screen but all the numbers are printing from 1-8130. We I try the loop by itself is prints fine but when I added to the rest of my code it is not working.

#include <stdio.h>
#include <iostream>
using namespace std;
#include<iomanip> 

int main() {
    int num =20,divisor,divisorSum,total;
    cout<<setw(2)<< "\n Number      Classification \n";
    cout <<"___________________________________"  <<"\n" ; 

     while (num<=8135)
       { total=0;    
         if (num>=20&&num<=30)
         { cout<<num<<"\n";
         }
         else if (num>=490&&num<=500)
         { cout<<num<<"\n";
         }     
         else if (num>=8120&&num<=8130)
         { cout<<num<<"\n";
         }  

          for (divisor = 1; divisor <= num / 2; ++divisor)
            if (num % divisor == 0)
           {                                
             total=total+divisor;

           } 


        if (total>num)
        {   cout<< setw(4)<<"\t"<<num<< "\tAbundant \n";
                 }        

                 else if (total<num)  
                 {   cout<< setw(4)<<"\t"<<num<<"\tDeficient \n";
                 }        

        else if (total=num)
       {  cout<< setw(4)<<"\t"<<num<<"\tPerfect \n";

             }  

            num++;




 }             

    system ("pause");
    return 0;
}

Would you want something like this on the end of the first if tree?

else
 	  {
 		 ++num;
 		 continue;
 	  }

Here you make an assignment where to likely meant to compare.

else if ( total==num )
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.