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

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.86 KB  |  hits: 12  |  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 <cstring>
  3. #include <vector>
  4. #include <math.h>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.         char a[10]; // Input
  10.         double a0, a1, r2, r3; // aX = input converted from string to numbers, rX = results for each of the three equations
  11.         vector<double> r1; // Vector instead of array because hell if I can remember how arrays in C++ work
  12.         bool asdf = true; // Loop control
  13.         while(asdf)
  14.         {
  15.                 asdf = false;
  16.                 cout<<"Input result for A(0): ";
  17.                 cin>>a;
  18.                 a0 = atof(a);
  19.                 if((a0 == 0) && (strcmp(a, "0") != 0)){asdf = true;} //This checks if the input is actually 0 when atof returns 0
  20.         }
  21.         asdf = true;
  22.         while(asdf)
  23.         {
  24.                 asdf = false;
  25.                 cout<<"Input result for A(1): ";
  26.                 cin>>a;
  27.                 a1 = atof(a);
  28.                 if((a1 == 0) && (strcmp(a, "0") != 0)){asdf = true;}
  29.         }
  30.         cout<<"n        A(n)            2^n             2.1^n\n";
  31.         cout<<"0        "<<a0<<"                1               1\n";
  32.         cout<<"1        "<<a1<<"                2               2.1\n";
  33.         r1.push_back(a0);
  34.         r1.push_back(a1);
  35.         for (int i = 2; i <= 20; i++)
  36.         { // Does all the equations and prints them out and junk
  37.                 r1.push_back((4 * r1[i-1]) - (4 * r1[i - 2]));
  38.                 r2 = pow(2.0, i);
  39.                 r3 = pow(2.1, i);
  40.                 cout<<i<<"      "<<r1[i]<<"             "<<r2<<"                "<<r3<<"\n";
  41.         }
  42.         fflush(stdin);
  43.         cin.get();
  44.         r1.clear();
  45.         asdf = true;
  46.         while(asdf)
  47.         {
  48.                 asdf = false;
  49.                 cout<<"Input result for B(0): ";
  50.                 cin>>a;
  51.                 a0 = atof(a);
  52.                 if((a0 == 0) && (strcmp(a, "0") != 0)){asdf = true;}
  53.         }
  54.         asdf = true;
  55.         while(asdf)
  56.         {
  57.                 asdf = false;
  58.                 cout<<"Input result for B(1): ";
  59.                 cin>>a;
  60.                 a1 = atof(a);
  61.                 if((a1 == 0) && (strcmp(a, "0") != 0)){asdf = true;}
  62.         }
  63.         r1.push_back(a0);
  64.         r1.push_back(a1);
  65.         cout<<"n        B(n)            1.5^n           1.8^n\n";
  66.         cout<<"0        "<<a0<<"                1               1\n";
  67.         cout<<"1        "<<a1<<"                1.5             1.8\n";
  68.         for (int i = 2; i <= 20; i++)
  69.         {
  70.                 r1.push_back((-r1[i-1]) + r1[i-2]);
  71.                 r2 = pow(1.5, i);
  72.                 r3 = pow(1.8, i);
  73.                 cout<<i<<"      "<<r1[i]<<"             "<<r2<<"                "<<r3<<"\n";
  74.         }
  75.         fflush(stdin);
  76.         cin.get();
  77.         return 0;
  78. }