Complex number in qudratic equation C++

This is a discussion on Complex number in qudratic equation C++ within the C++ Programming forums, part of the General Programming Boards category; hi I need help with this program, I have to write an easy code for complex number thank you if ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    2

    Complex number in qudratic equation C++

    hi I need help with this program, I have to write an easy code for complex number thank you

    if I put a=1, b=2. c=2 then I should get x=-1+j.1 and y=-1-j.1. I am an engineer so I use j instead of i.

    #include <iostream>
    #include <math.h>

    using namespace std;

    int main()

    {
    float a=0.0;
    float b=0.0;
    float c=0.0;
    float d=0.0;
    float x=0.0;
    float y=0.0;

    cout <<"value of a:";
    cin>>a;
    cout <<"value of b:";
    cin>>b;
    cout <<"value of c:";
    cin>>c;

    d=sqrt(b*b-4*a*c);
    x=(-b+d)/(2*a);
    y=(-b-d)/(2*a);

    if (x==y)
    {
    cout<<"Both roots are equal\n";
    }
    else(x!=y)
    {
    cout<<"The roots are not the same\n";
    }

    cout<<x;
    cout<<y;
    cout<<"\n";

    return 0;

    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,420
    Come back when you've learnt to read
    << !! Posting Code? Read this First !! >>
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Code:
    else(x!=y)
    {
    cout<<"The roots are not the same\n";
    }
    Try just 'else' not with the (x!=y)
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #4
    Registered User
    Join Date
    Oct 2004
    Posts
    2
    man I just asked u didnt had to eat my head
    is that forum is for when u don know ask other people thats what I am doing

    now thank you jawib

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    1,197
    Eating heads?? Salem pointed out that if you post code you use codetags. Nothing more, nothing less, but some people can/will be annoyed when you post code without codetags, especially since there is a sticky saying that you should/must use codetags.

  6. #6
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    also realize that there is a standard complex class in <complex>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05:55 PM
  2. Replies: 6
    Last Post: 02-19-2009, 06:19 PM
  3. Issue w/ Guess My Number Program
    By mkylman in forum C++ Programming
    Replies: 5
    Last Post: 08-23-2007, 01:31 AM
  4. Random number + guessing game trouble
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-08-2007, 03:33 AM
  5. Perfect number...
    By Argo_Jeude in forum C++ Programming
    Replies: 8
    Last Post: 07-12-2005, 01:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21