DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: float vs double

  1. #1
    Adam Guest

    float vs double


    hey i am writing this program to do some simple calculations but i declare
    the variables as double...but if the inputs are not an integer and dont =
    an output that is an integer it crashes...how can i change it so that it
    is float...this is the code...

    #include <iostream.h>
    #include <iomanip.h>

    int main()
    {
    double a11,a12,a21,a22,x1,x2,c1,c2,numerator1,numerator2,denominator;

    cout << "please enter the value of a11 ";
    cin >> a11;
    cout << "please enter the value of a12 ";
    cin >> a12;
    cout << "please enter the value of a21 ";
    cin >> a21;
    cout << "please enter the value of c1 ";
    cin >> c1;
    cout << "please enter the value of c2 ";
    cin >> c2;

    numerator1 = (c1 * a22) - (c2 * a12);
    numerator2 = (c2 * a11) - (c1 * a21);
    denominator = (a11 * a22) - (a12 * a21);
    x1 = (numerator1 / denominator);
    x2 = (numerator2 / denominator);

    cout << "the answer for x1 = " << x1 <<endl;
    cout << "the answer for x2 = " << x2 <<endl;

    return 0;
    }

  2. #2
    Steve F Guest

    Re: float vs double



    I think you forgot to set a22, as in:

    cout << "please enter the value of a22 ";
    cin >> a22;

    Steve

    "Adam" <djatom4@hotmail.com> wrote:
    >
    >hey i am writing this program to do some simple calculations but i declare
    >the variables as double...but if the inputs are not an integer and dont

    =
    >an output that is an integer it crashes...how can i change it so that it
    >is float...this is the code...
    >
    >#include <iostream.h>
    >#include <iomanip.h>
    >
    >int main()
    >{
    > double a11,a12,a21,a22,x1,x2,c1,c2,numerator1,numerator2,denominator;
    >
    > cout << "please enter the value of a11 ";
    > cin >> a11;
    > cout << "please enter the value of a12 ";
    > cin >> a12;
    > cout << "please enter the value of a21 ";
    > cin >> a21;
    > cout << "please enter the value of c1 ";
    > cin >> c1;
    > cout << "please enter the value of c2 ";
    > cin >> c2;
    >
    > numerator1 = (c1 * a22) - (c2 * a12);
    > numerator2 = (c2 * a11) - (c1 * a21);
    > denominator = (a11 * a22) - (a12 * a21);
    > x1 = (numerator1 / denominator);
    > x2 = (numerator2 / denominator);
    >
    > cout << "the answer for x1 = " << x1 <<endl;
    > cout << "the answer for x2 = " << x2 <<endl;
    >
    > return 0;
    >}



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center