Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 6th, 2012  |  syntax: None  |  size: 1.42 KB  |  hits: 40  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. typedef unsigned int Uint;
  5.  
  6. using namespace std;
  7.  
  8.  
  9. int main (int argc, char * const argv[])
  10. {
  11.         double T2;
  12.         double maxValue;
  13.         double T1;
  14.         double scale = 1;
  15.     // insert code here...
  16.        
  17.         cout << "\nEntering\nEnter Max Value : ";
  18.         cin >> maxValue;
  19.        
  20.         // Find the ideal scale
  21.         for(;maxValue*scale < .0001;)
  22.         {
  23.                 // Up scale.
  24.                 scale*=10;     
  25.         }
  26.        
  27.         maxValue*=scale;
  28.         cout << "\nEnter Start Value : ";
  29.         cin >> T1;
  30.        
  31.         // Find the ideal scale
  32.         for(;T1*scale < .0001;)
  33.         {
  34.                 // Up scale.
  35.                 scale*=10;     
  36.                 maxValue*=10;
  37.         }
  38.        
  39.         T1*=scale;
  40.         cout << "\nEnter Second Value: ";
  41.         cin >> T2;
  42.        
  43.         for(;T2*scale < .0001;)
  44.         {
  45.                 // Up scale.
  46.                 scale*=10;
  47.                 maxValue*=10;
  48.                 T1*=10;
  49.         }
  50.        
  51.         T2*=scale;
  52.        
  53.         double ratio = T2/T1;
  54.        
  55.         while(1)
  56.         {
  57.                 for(Uint Tn = 1;;++Tn)
  58.                 {
  59.                         if(maxValue > T1)
  60.                         {
  61.                                 if(T1*pow((ratio), (double) Tn) > maxValue)
  62.                                 {  
  63.                                         cout << "\n*--------------*\nFound it: n is " << Tn << "\n\n";
  64.                                         break;
  65.                                 }
  66.                         }
  67.                        
  68.                         else
  69.                         {
  70.                                 if(T1*pow((ratio), (double) Tn) < maxValue)
  71.                                 {  
  72.                                         cout << "\n*--------------*\nFound it: n is " << Tn << "\n\n";
  73.                                         break;
  74.                                 }  
  75.                         }
  76.                 }
  77.                
  78.                 cout << "\nDo new calc? ";
  79.                
  80.                 char result;
  81.                 cin >> result;
  82.                
  83.                 if(result == 'q')
  84.                         return 1;
  85.                 //otherwise
  86.                
  87.                 cout << "\nEnter Start Value : ";
  88.                 cin >> T1;
  89.                 cout << "\nEnter Second Value: ";
  90.                 cin >> T2;
  91.         }
  92.     return 0;
  93. }