Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- int main()
- {
- int rows = 0;
- float x = 0.0;
- float increment = 0.0;
- float ex = 0.0;
- float lo = 0.0;
- float sq = 0.0;
- int triesInMax = 0;
- int triesInError = 0;
- int const TRIESMAX = 5;
- int const TRIESERROR = (TRIESMAX - 1);
- int const TRIESDONE = 0;
- int const ROWMIN = 0;
- int const ROWMAX = 35;
- float const XMIN = 0.0;
- float const XMAX = 100.0;
- float const INCMIN = 0.0;
- triesInMax = TRIESMAX;
- triesInError = TRIESERROR;
- while(rows <= ROWMIN || rows > ROWMAX)
- {
- if(triesInMax <= triesInError && triesInMax > TRIESDONE)
- {
- cout << "The number you entered was invalid, TRY AGAIN: " << endl;
- }
- cout << "Enter the number of rows in the table to be produced " << endl << "The number of rows must be between " << ROWMIN << " and " << ROWMAX << endl;
- cin >> rows;
- triesInMax--;
- if(triesInMax <= TRIESDONE)
- {
- cerr << "ERROR, ATTEMPTED TOO MANY TIMES!";
- return 1;
- }
- }
- triesInMax = TRIESMAX;
- triesInError = TRIESERROR;
- while(x == XMIN || abs(x) > XMAX)
- {
- if(triesInMax <= triesInError && triesInMax > TRIESDONE)
- {
- cout << "The number you entered was too large, TRY AGAIN: " << endl;
- }
- cout << "Enter the starting X " << endl << "The starting x must satisfy |X| " << fixed << setprecision(0) << XMAX << endl;
- cin >> x;
- triesInMax--;
- if(x == XMIN)
- {
- break;
- }
- if(triesInMax <= TRIESDONE)
- {
- cerr << "ERROR, ATTEMPTED TOO MANY TIMES!";
- return 2;
- }
- }
- triesInMax = TRIESMAX;
- triesInError = TRIESERROR;
- while(increment <= INCMIN)
- {
- if(triesInMax <= triesInError && triesInMax > TRIESDONE)
- {
- cout << "The number you entered was invalid, TRY AGAIN: " << endl;
- }
- cout << "Enter the increment in X between successive rows " << endl << "The increment in X must be positive " << endl;
- cin >> increment;
- triesInMax--;
- if(triesInMax <= TRIESDONE)
- {
- cerr << "ERROR, ATTEMPTED TOO MANY TIMES!";
- return 3;
- }
- }
- cout << endl << endl << endl << endl << fixed << setw(9) << right << "X" << setw(17) << "exp(X)" << setw(16) << "log10(X)" << setw(15) << "sqrt(X)" << endl;
- while(rows > ROWMIN)
- {
- cout << fixed << right << setw(12) << setprecision(3) << x;
- ex = exp(x);
- cout << fixed << right << setw(15) << setprecision(2) << scientific << ex;
- if(x <= XMIN)
- {
- cout << fixed << right << setw(15) << "undef";
- }
- else
- {
- lo = log10(x);
- cout << fixed << right << setw(15) << setprecision(5) << lo;
- }
- sq = sqrt(abs(x));
- cout << fixed << right << setw(15) << setprecision(5) << sq;
- if(x <= XMIN)
- {
- cout << "i";
- }
- cout << endl;
- x += increment;
- rows--;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement