
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 1.86 KB | hits: 12 | expires: Never
#include <iostream>
#include <cstring>
#include <vector>
#include <math.h>
using namespace std;
int main()
{
char a[10]; // Input
double a0, a1, r2, r3; // aX = input converted from string to numbers, rX = results for each of the three equations
vector<double> r1; // Vector instead of array because hell if I can remember how arrays in C++ work
bool asdf = true; // Loop control
while(asdf)
{
asdf = false;
cout<<"Input result for A(0): ";
cin>>a;
a0 = atof(a);
if((a0 == 0) && (strcmp(a, "0") != 0)){asdf = true;} //This checks if the input is actually 0 when atof returns 0
}
asdf = true;
while(asdf)
{
asdf = false;
cout<<"Input result for A(1): ";
cin>>a;
a1 = atof(a);
if((a1 == 0) && (strcmp(a, "0") != 0)){asdf = true;}
}
cout<<"n A(n) 2^n 2.1^n\n";
cout<<"0 "<<a0<<" 1 1\n";
cout<<"1 "<<a1<<" 2 2.1\n";
r1.push_back(a0);
r1.push_back(a1);
for (int i = 2; i <= 20; i++)
{ // Does all the equations and prints them out and junk
r1.push_back((4 * r1[i-1]) - (4 * r1[i - 2]));
r2 = pow(2.0, i);
r3 = pow(2.1, i);
cout<<i<<" "<<r1[i]<<" "<<r2<<" "<<r3<<"\n";
}
fflush(stdin);
cin.get();
r1.clear();
asdf = true;
while(asdf)
{
asdf = false;
cout<<"Input result for B(0): ";
cin>>a;
a0 = atof(a);
if((a0 == 0) && (strcmp(a, "0") != 0)){asdf = true;}
}
asdf = true;
while(asdf)
{
asdf = false;
cout<<"Input result for B(1): ";
cin>>a;
a1 = atof(a);
if((a1 == 0) && (strcmp(a, "0") != 0)){asdf = true;}
}
r1.push_back(a0);
r1.push_back(a1);
cout<<"n B(n) 1.5^n 1.8^n\n";
cout<<"0 "<<a0<<" 1 1\n";
cout<<"1 "<<a1<<" 1.5 1.8\n";
for (int i = 2; i <= 20; i++)
{
r1.push_back((-r1[i-1]) + r1[i-2]);
r2 = pow(1.5, i);
r3 = pow(1.8, i);
cout<<i<<" "<<r1[i]<<" "<<r2<<" "<<r3<<"\n";
}
fflush(stdin);
cin.get();
return 0;
}