need help.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ayman723
    New Member
    • Sep 2006
    • 40

    need help.

    hello everyone;

    can anyone tell me whats wrong with this simple code??

    #include <iostream>

    #include <cmath>


    int main()
    {
    int x;

    cout<<"enter a number ";
    cin>> "x";
    cout<< sqrt( x );





    return 0;
    }
  • gasfusion
    New Member
    • Sep 2006
    • 59

    #2
    might want to use a float for x instead of integer, especially if you're squarerooting.

    Comment

    • ayman723
      New Member
      • Sep 2006
      • 40

      #3
      thanks fo the answer but i tried it and its not working;

      #include <iostream>

      #include <cmath>


      int main()
      {
      float x;

      cout<<"enter a number ";
      cin>> "x";
      cout<< sqrt( x );





      return 0;
      }

      Comment

      • ayman723
        New Member
        • Sep 2006
        • 40

        #4
        Originally posted by gasfusion
        might want to use a float for x instead of integer, especially if you're squarerooting.
        thanks fo the answer but i tried it and its not working;

        #include <iostream>

        #include <cmath>


        int main()
        {
        float x;

        cout<<"enter a number ";
        cin>> "x";
        cout<< sqrt( x );

        Comment

        • ayman723
          New Member
          • Sep 2006
          • 40

          #5
          need help

          thanks fo the answer but i tried it and its not working;

          #include <iostream>

          #include <cmath>


          int main()
          {
          float x;

          cout<<"enter a number ";
          cin>> "x";
          cout<< sqrt( x );

          Comment

          • zeny
            New Member
            • Jul 2006
            • 44

            #6
            Here“s your solution:

            #include <iostream>
            #include <stdlib.h>
            #include <cmath>


            int main(){

            int x;

            cout<<"enter a number ";
            cin>> x;
            cout<< sqrt( x );

            system("PAUSE") ;
            return 0;
            }


            I tested and it works. The problem in your code was in the input of x, on your code u have the statement cin>>"x".

            Regards

            Comment

            • gasfusion
              New Member
              • Sep 2006
              • 59

              #7
              Sorry wasn't looking hard enough. You were saving into a character x instead of float variable x.
              Code:
              #include <iostream>
              #include <cmath> 
              #include <conio.h>
              using namespace std;
              
              int main()
              {
              float x;
              
              cout << "enter a number: "; cin >> x;
              cout<< sqrt( x ); 
              
              getche();
              return 0;
              }

              Comment

              • zeny
                New Member
                • Jul 2006
                • 44

                #8
                x doesnt need to be float

                Comment

                • ayman723
                  New Member
                  • Sep 2006
                  • 40

                  #9
                  thank you zeny

                  but how can i do it?

                  Comment

                  • Banfa
                    Recognized Expert Expert
                    • Feb 2006
                    • 9067

                    #10
                    Originally posted by ayman723
                    can anyone tell me whats wrong with this simple code??
                    Have you received the answer you require?

                    One of the problems people have had answering your question is that you never actually stated what the original problem was. You should have described the output you where getting and the output you where expecting.

                    Comment

                    Working...