Guest User

Untitled

a guest
Feb 21st, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. int tayExp() {
  2.     int choice, maxLoops=10;
  3.     double number = 1;
  4.     int iter, i;
  5.     float result=1.0f;
  6.     double fact=1.0, pow=1.0;
  7.     cout << "To what degree would you like to estimate e?: ";
  8.     cin >> number;
  9.     cout << endl << "Doing some math..." << endl;
  10.     result = 0.000000000000f;
  11.     iter = 0;
  12.     while ( iter < maxLoops ) {
  13.         fact = 1;
  14.         pow = 1;
  15.         for ( i = 0; i < iter; i++ ) {
  16.             pow *= number;
  17.         }
  18.         for ( i = iter; i > 1; i-- ) {
  19.             fact *= i;
  20.         }
  21.         result += pow/fact;
  22.         iter++;
  23.         cout << "*" << iter <<  " * " << result << "*" << endl;
  24.         if ( (iter % 9) == 0 ) {
  25.             cout << "Would you like to see ten more? (1 for yes, 0 for no): ";
  26.             cin >> choice;
  27.             switch ( choice ) {
  28.                 case 0:
  29.                     return 0;
  30.                     break;
  31.                 case 1:
  32.                     maxLoops += 10;
  33.                     continue;
  34.                     break;
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment