
Untitled
By: a guest on
May 6th, 2012 | syntax:
None | size: 1.42 KB | hits: 40 | expires: Never
#include <iostream>
#include <cmath>
typedef unsigned int Uint;
using namespace std;
int main (int argc, char * const argv[])
{
double T2;
double maxValue;
double T1;
double scale = 1;
// insert code here...
cout << "\nEntering\nEnter Max Value : ";
cin >> maxValue;
// Find the ideal scale
for(;maxValue*scale < .0001;)
{
// Up scale.
scale*=10;
}
maxValue*=scale;
cout << "\nEnter Start Value : ";
cin >> T1;
// Find the ideal scale
for(;T1*scale < .0001;)
{
// Up scale.
scale*=10;
maxValue*=10;
}
T1*=scale;
cout << "\nEnter Second Value: ";
cin >> T2;
for(;T2*scale < .0001;)
{
// Up scale.
scale*=10;
maxValue*=10;
T1*=10;
}
T2*=scale;
double ratio = T2/T1;
while(1)
{
for(Uint Tn = 1;;++Tn)
{
if(maxValue > T1)
{
if(T1*pow((ratio), (double) Tn) > maxValue)
{
cout << "\n*--------------*\nFound it: n is " << Tn << "\n\n";
break;
}
}
else
{
if(T1*pow((ratio), (double) Tn) < maxValue)
{
cout << "\n*--------------*\nFound it: n is " << Tn << "\n\n";
break;
}
}
}
cout << "\nDo new calc? ";
char result;
cin >> result;
if(result == 'q')
return 1;
//otherwise
cout << "\nEnter Start Value : ";
cin >> T1;
cout << "\nEnter Second Value: ";
cin >> T2;
}
return 0;
}