Advertisement
StormWingDelta

LCM - tester

Jan 14th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.20 KB | None | 0 0
  1. //Need some help making this easier to use.
  2.  
  3.     bool NextP = true; //outer loop
  4.     int Up = 1, N1 = 2, N2 = 1;
  5.     unsigned long int Mul = 0, Dev = 0;
  6.     int Fixer = 0;
  7.  
  8.     //LCM - Least Common Multiple
  9.    
  10.     while(NextP)
  11.     {
  12.         Up = 1;
  13.         N1 = 0;
  14.         N2 = 0;
  15.         if(NextP)
  16.         {
  17.             printf("Enter both numbers below.... \n");
  18.             printf("The first number must be larger than the second number\n");
  19.             printf("Enter 0 for both numbers to exit. \n");
  20.             cin >> N1 >> N2;
  21.             cout << endl;
  22.            
  23.         }
  24.         else
  25.         {
  26.             printf("Exiting Program! \n");
  27.         }
  28.         if(N1 != 0 && N2 != 0)
  29.         {
  30.             //LCM loops start
  31.             if( (N1 > N2) )
  32.             {
  33.                 do
  34.                 {
  35.                     Mul = N2 * Up;
  36.                     //cout << N1 << " * " << Up << " = " << Mul <<endl;
  37.                     Dev = Mul / N1;
  38.                     //printf(" %f / %f = %f \n",Mul,N2,Dev);
  39.                    
  40.                     printf("Loop %d \n",(int)Up);
  41.                     Up++;
  42.                 }
  43.                 while(!IsWholeNumberFloat(Mul, N1));
  44.                 Fixer = (int)Up - 1;
  45.                 printf("Whole Number After %d Loops\n\n", Fixer);
  46.                 if(IsWholeNumber(Mul, Fixer))
  47.                 {
  48.                     //printf("These are the hole numbers");
  49.                     cout << N2 << " * " << Up - 1 << " = " << Mul <<endl;
  50.                     cout << Mul << " / " << N1 << " = " << Dev << endl;
  51.                 }
  52.             }
  53.             else if((N2 > N1))
  54.             {
  55.                 do
  56.                 {
  57.                     Mul = N1 * Up;
  58.                     //cout << N1 << " * " << Up << " = " << Mul <<endl;
  59.                     Dev = Mul / N2;
  60.                     //printf(" %f / %f = %f \n",Mul,N2,Dev);
  61.                    
  62.                     printf("Loop %d \n",(int)Up);
  63.                     Up++;
  64.                 }
  65.                 while(!IsWholeNumberFloat(Mul, N2));
  66.                 Fixer = (int)Up - 1;
  67.                 printf("Whole Number After %d Loops\n\n", Fixer);
  68.                 if(IsWholeNumber(Mul, Fixer))
  69.                 {
  70.                     //printf("These are the hole numbers");
  71.                     cout << N1 << " * " << Up - 1 << " = " << Mul <<endl;
  72.                     cout << Mul << " / " << N2 << " = " << Dev << endl;
  73.                 }
  74.             }
  75.             else
  76.             {
  77.                 system("cls");
  78.                 cout << "Programming or Input Error of some kind!?!?!?" << endl;
  79.                 cout << "OR" << endl;
  80.                 cout << "I just didn't want to show the math for two of the same number!" << endl;
  81.                 cout << "OR" << endl;
  82.                 cout << "You needed a clearing of the screen?" << endl;
  83.                 cout << endl;
  84.             }
  85.             //LCM loops end
  86.            
  87.         }
  88.         else if(N1 == 0 && N2 == 0)
  89.         {
  90.             NextP = false;
  91.             printf("Exiting Program! \n");
  92.         }
  93.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement