Thread: Kindly help!!!

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    112

    Exclamation Kindly help!!!

    hi this is Fatima..!! i have started C++ programming few days back..!!
    i am given an assignment fer homewrk.In the prob i have to take the sqr root but i dun knw how to take square root.
    the code is


    Code:
    #include<iostream.h>
    #include<conio.h>
    void main()
    {
    clrscr();
    int roots1,roots,a,b,c;
    cout<<"Enter value of a=";
    cin>>a;
    cout<<"Enter value of b=";
    cin>>b;
    cout<<"Enter value of c=";
    cin>>c;
    
    if  (b*b- 4*a*c==0)
    {
    cout<<"Roots are single,equal";
    }
    else if (b*b-4*a*c>0)
    {
    cout<<"Equation has two real roots";
    }
    else if (b*b-4*a*c<0)
    {
    cout<<"Equation has two complex roots";
    }
    else if (b*b-4*a*c>=0)
    {
    roots=-b+sqrt(b*b-4*a*c)/2*a;
    roots1=-b-sqrt(b*b-4*a*c)/2*a;
    cout<<"The roots are"<<roots<<roots1<<endl;
    }
    getch();
    }
    in the last part if b^2-4ac is greater than and equal to zero then i have to take square root of it..and display the roots but i dun knw how to..!!

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    You seem to use an aincent compiler.
    When I use the new headers and include the math header it compiles fine.
    Code:
    // #include<iostream.h>
    #include<iostream>  // use that instead
    #include<cmath>  // for std::sqrt
    
    using namespace std;  // reqired with the modern headers
    
    // void main() {
    int main() {  // Main returns int
    
        int roots1,roots,a,b,c;
        cout<<"Enter value of a=";
        cin>>a;
        cout<<"Enter value of b=";
        cin>>b;
        cout<<"Enter value of c=";
        cin>>c;
        
        if  (b*b- 4*a*c==0)
        {
            cout<<"Roots are single,equal";
        }
        else if (b*b-4*a*c>0)
        {
            cout<<"Equation has two real roots";
        }
        else if (b*b-4*a*c<0)
        {
            cout<<"Equation has two complex roots";
        }
        else if (b*b-4*a*c>=0)
        {
            roots=-b+sqrt(b*b-4*a*c)/2*a;
            roots1=-b-sqrt(b*b-4*a*c)/2*a;
            cout<<"The roots are"<<roots<<roots1<<endl;
        }
    }
    Kurt

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    112
    thnx...then how to upgrade the compiler..???

  4. #4
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by Fatima Rizwan View Post
    thnx...then how to upgrade the compiler..???
    What are you using ?
    Kurt

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    596
    Your code will probably compile if you simply add
    Code:
    #include <math.h>

  6. #6
    Registered User
    Join Date
    Apr 2004
    Location
    Ohio
    Posts
    147
    If you're using Windows, get Visual Studio Express, Dev-C++ or Code::Blocks -- all are free and all use modern compilers and provide powerful IDE's and debuggers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Kindly Explain the reason behind this?
    By chottachatri in forum C++ Programming
    Replies: 3
    Last Post: 02-24-2008, 10:10 AM
  2. C program - Kindly help
    By psriram in forum C Programming
    Replies: 2
    Last Post: 12-30-2007, 09:08 AM
  3. Replies: 18
    Last Post: 06-14-2003, 10:40 AM