lets try this one more time, I need some help please!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DaRok28
    New Member
    • Feb 2007
    • 8

    lets try this one more time, I need some help please!

    Code:
    I also need some help 
    --------------------------------------------------------------------------------
    
    #include <iostream>
    #include <cmath>
    using namespace std;
    
    int main()
    {
       char cAgain;
       int iDataset = 1;
       double dRoot, dValuea, dValueb, dValuec;
    
       cout.setf(ios::fixed);
       cout.setf(ios::showpoint);
       cout.precision(4);
    
       do
       {
          cout << endl << "****************" << endl
               << "* Data Set " << iDataset << " *" << endl
               << "****************" << endl << endl;
          cout << endl << "Please enter coefficients for quadratic equation"
               << " ax^2 + bx + c = 0" << endl << endl;
          cout << endl << "Value of 'a' : " << endl;
          cin >> dValuea;
          cout << "Value of 'b' : " << endl;
          cin >> dValueb;
          cout << "Value of 'c' : " << endl;
          dRoot = (- dValueb +/- sqrt(pow(dValueb, 2) - 4 * dValuea * dValuec))/ 2 * dValuea;
          cout << endl << "You have entered the equation " << dValuea
               << "x^2 + " << dValueb << "x + " << dValuec << " = 0" << endl;
          cout << endl << "The root to this equation is: " << endl << endl << dRoot;
          cout << endl << "Want to do this again? Y/y/N/n" << endl << endl;
          cin >> cAgain;
          iDataset++;
       } while (cAgain == 'Y' || cAgain == 'y');
    
       return 0;
    }
    Here is my program and I dont care if this works as much as I need to know what this error means
    program2.cpp:38 : error: expected primary-expression before '/' token
    line 38 starts with dRoot =
    Last edited by Ganon11; Mar 4 '07, 11:40 PM. Reason: code tags added, indented
  • stroken
    New Member
    • Mar 2007
    • 24

    #2
    Hi,
    I just took a quick glance at your code, but the problem seems to be in this row:

    Code:
    dRoot = (- dValueb +/- sqrt(pow(dValueb, 2) - 4 * dValuea * dValuec))/ 2 * dValuea;
    In C++ you can“t write "+/-", replace the line with the following two lines

    Code:
    dRoot1 = (- dValueb + sqrt(pow(dValueb, 2) - 4 * dValuea * dValuec))/ 2 * dValuea;
    dRoot2 = (- dValueb - sqrt(pow(dValueb, 2) - 4 * dValuea * dValuec))/ 2 * dValuea;
    ... and of course declare dRoot1 and dRoot2.

    Did this help?

    Comment

    Working...