Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ Help! Please!

Name: Amna Umen 2008-04-02 18:37

Ok so i'm working on my project that integrates using the simpson method. I have the code for the first part done, but now i'm getting this bullshit "multiple declaration for 'fout'"

What the hell does that mean?! I only have the ofstream fout up at the top. Any help would be appreciated here, or if someone has a working code for this. I'm dying over this. Here's the code.

#include <conio.h>
#include <fstream.h>
#include <iomanip.h>
#include <iostream.h>
#include <math.h>

ofstream fout;

int main ()
  {
    // Variable Declarations
    char input;
    int equa, i, j, k, u;
    double a, b, coef[10], fa, fb, fx, r, delta, told, x, tnew, snew, uplim;

    // Alphabetized Variable Dictionary
    //==========================================================================
    // a: Used in equation
    // b: Used in equation
    // coef[10]: Where the coefficient is stored
    // equa: Number of equations
    // fa: Stores the value of fa
    // fb: Stores the value of fb
    // fx: Degree of accuracy
    // i:  Centering aid
    // reply: Used to store yes or no inputs
    // j:  used in the input of coefficients
    // k:  Iteration counter
    // r: The root of the polynomaial
    // u:  The highest power of x
    //==========================================================================

    fout.open ("integral.txt");

    cout << fixed << setprecision (4);
    fout << fixed << setprecision (4);

    // Program Start
    for ( i = 1; i <= 8; i++ )
      {
        cout << endl;
      }

    cout << setw (50) << "Integral Solver";

    cout << endl << endl << endl;

    cout << setw (57) << "Solves the Integral Using Simpsons Method";

    cout << endl << endl << endl;

    cout << setw (50) << "Strike Enter to start";

    cin.get ();

    equa = 0;
    k = 0;

     do
        {
          clrscr ();

          for ( i = 1; i <= 12; i++ )
            {
              cout << endl;
            }

          // Prompts user for Highest Power of polynomial
          cout << setw (61) << "Input the polynomial's highest power: ";
          cin >> u;
          clrscr ();

          // Prompt user for coefficients
          for ( j = u; j >= 0; j-- )
            {
              for ( i = 1; i <= 12; i++ )
                {
                  cout << endl;
                }

              cout << setw (53) << "Input the Coefficent of x^" << j << ": ";
              cin >> coef[j];
              clrscr ();
            }

          // Prompts user for bounds
          cout << setw (61) << "Input the integrals upper bound";
          cin >> b;

          cout << setw (53) << "Input the integrals lower bound";
          cin >> a;
          clrscr ();

          do
            {
              clrscr ();

              // Prompts user if the equation is correct
              for ( i = 1; i <= 7; i++ )
                {
                  cout << endl;
                }

              cout << setw (42) << "Function #" << equa << ": ";

              cout << endl << endl << endl ;


              switch (u)
               {
                 case 9: ;
                 case 8: ;
                 case 7: cout << "f(x) = " ;
                   break;
                 case 6: cout << setw(8) << "f(x) = ";
                   break;
                 case 5: cout << setw(13) << "f(x) = ";
                   break;
                 case 4: cout << setw(18) << "f(x) = ";
                   break;
                 case 3: cout << setw(23) << "f(x) = ";
                   break;
                 case 2: cout << setw(28) << "f(x) = ";
                   break;
                 case 1: cout << setw(33) << "f(x) = ";
                   break;
                 case 0: cout << setw(38) << "f(x) = ";
               }

            for (j = u; j >= 1; j--)
            {
            cout << coef [j] <<  "x^" << u << " + ";
            }
              cout << coef[0] << "x^0";

              cout << endl << endl << endl;

              cout << setw (52) << "Is f(x) correct?  (y/n)? ";

              cin >> input;
            }

          while ((input != 'n') && (input != 'N') &&
                (input != 'y') && (input != 'Y'));
        }

      while ((input == 'n') || (input == 'N'));
      }
      fout << setw (43) << "Bisection Method" << endl << endl;
      fout << setw (40) << "Equation # " << equa << endl << endl;

      clrscr ();
      b = 0;
      fb = 0;
      // Evaluate fb using horner's method
      for ( i = u; i >= 0; i-- );
        {
          fb = fb * b + coef [i];
        }

      do
        {
          a = b;
          fa = fb;
          b = a + 1;
          fb = 0;

          for ( i = u; i >= 0; i-- )
            {
              fb = fb * b + coef [i];
            }
        }

      while (fa * fb >= 0);

      fout << setw (25) << "k" << setw (10) << "x" << setw (10);
      fout << "fx" << endl << endl;

//Begin calculations
        k = 0;
        delta = b - a;
        told = delta *(fa + fb) / 2;
        k = k + 1;
        delta = delta / 2;
        x = a + delta;
        tnew = told / 2 + delta * fx;
        snew = (4 * tnew - told) / 3;
        uplim = pow (2, k - 1);

        cout << uplim;

        cin.get();
      // Prompt user if there is another function
      do
        {
          clrscr ();

          for ( j = 1; j <= 12; j++ )
            {
              cout << endl;
            }

          cout << setw (58) << "Is there another function? (y/n)? ";


          cin >> input;
        }

        while ((input != 'n') && (input != 'N') &&
               (input != 'y') && (input != 'Y'));

        fout << "\f";


    fout.close();
    return 0;
    }














Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List