Thread: Help on quadratic formula DOS program

  1. #1
    Registered User
    Join Date
    Jul 2005

    Help on quadratic formula DOS program

    Hate to do double threads but I felt this was a totally different issue that needed to be addressed. Here goes:

    #include <iostream>
    #include <cmath>
    using namespace std;
    float Quad(float x, float y, float z);
    int main() {
        float a;
        float b;
        float c;
        float funcvarb;
        cout << "\tQuadratic Formula is Fun!! (that's why this is doing it for you) "<< endl;
        cout << "\t\tInput the coefficients to the quadratic equation!" << endl;
        cout << "(A)X^2 input a please" ;
        cin >> a;
        cout << "\n(B)X   input b please" ;
        cin >> b;
        cout << "\n(C)    input c please" ;
        cin >> c;
        funcvarb = Quad(a, b, c);
        cout << "X = " << funcvarb << endl;
        return 0;
    float Quad(float x, float y, float z) {
          float plusanswer;
          float minusanswer;
          plusanswer = ((-y + sqrt((y*y) - 4(x)(z)))/2x)
          minusanswer = ((-y - sqrt((y*y) - 4(x)(z)))/2x)
          return (plusanswer, minusanswer);
    I had the idea of making the Quadratic formula work...but you know how that goes. Also, I want to know if i can let it do imaginary by :
    let sqrt(-1) = i

    Something of that nature. Whatever. I just had a mere idea of how to implement this. Let me tell you the errors!
    Basically the only thing is that it says i can't use 4 and 2 as a function because when i say
    it assumes it's a function. How do I fix this? Much help is appreciated. I hope I have good structure and everything

  2. #2
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    You're forgetting you are programming when you wrote this. 2x, 2(x)(y).. these things are correct in math, but in programming you need to have operations.

    Just replace the part of this line: 4(x)(z)))/2x, with this: (4*x*z)))/(2*x). You also are missing the semicolon on those two lines. You are also returning two values, when only one can be stored, so you're going to have to cout them in the Quad function, or return a struct.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Returning a struct or, more simply, a std::pair seems to be the appropriate design choice here. Also, cin.get() really has no logical place in your function (that is, the purpose of the function is not input and output; make the call after your function call if you so desire).

    Additionally, if you want to deal with complex numbers as well, look into std::complex.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. Need help with quadratic formula functions
    By orikon in forum C++ Programming
    Replies: 10
    Last Post: 10-15-2005, 04:49 PM
  3. Distance Formula in my program..... I need help fast!!!
    By Mackology101 in forum C Programming
    Replies: 3
    Last Post: 09-23-2004, 10:10 PM
  4. Compiling a program in VC++ and run it in DOS
    By Willhunting in forum A Brief History of
    Replies: 1
    Last Post: 01-18-2003, 04:09 AM
  5. initialising a DOS program from a C enviroment
    By Robert_Ingleby in forum C Programming
    Replies: 5
    Last Post: 03-07-2002, 01:53 PM