Float variable,but does not read float values!

Discussion in 'Computer Science & Culture' started by S.Tarafdar, May 19, 2003.

Thread Status:
Not open for further replies.
  1. S.Tarafdar Registered Senior Member

    Messages:
    35
    Please see the simple program below:
    #include<iostream.h>

    int main()
    {
    float number,squre_value;
    cout<<"Enter a number";
    cin>>number;
    squre_value=number*number;
    cout<<number<<"*"<<number"="squre_value;
    return 0;

    }

    It works with integer value,but not with float values.Please tell me ,why?
     
    Last edited: May 20, 2003
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. AntonK Technomage Registered Senior Member

    Messages:
    1,083
    Wow, you're code managed to mess up sciforums code for some reason....hope its not just for me. Can a mod fix it so that we can read it and help out?

    -AntonK
     
  4. Google AdSense Guest Advertisement



    to hide all adverts.
  5. S.Tarafdar Registered Senior Member

    Messages:
    35
    Invisible codes!

    Dear AntonK,
    I do not know how I can put my codes here so that all are visible.
    Please help me out.

    Thanks
     
  6. Google AdSense Guest Advertisement



    to hide all adverts.
  7. AntonK Technomage Registered Senior Member

    Messages:
    1,083
    I've never seen this happen..im gonna try to get a mod to help (actually, I'd very much like to BE mod for the Computer Science forum...if it ever comes up

    Please Register or Log in to view the hidden image!

    ) Do you have somewhere you can post it? A website perhaps? Then link it here? We can help out that way.

    -AntonK

    (My other suggestion is, and i dont know if it will work, is to use the [C0DE] and [/C0DE] tags...I think that will work. Just replace my zeros with O's and it should work, and be formated better.) Should look like this.

    Code:
    int main()
    {
         int mySampleCode = 25;
         printf("This code should look correctly.\n");
         printf("Lets hope it does\t\tmySampleCode = %d\n", mySampleCode);
         return 1;
    }
    
    -AntonK
     
  8. S.Tarafdar Registered Senior Member

    Messages:
    35
    Turbo c++ compiler

    Yes,I am writing the codes here:


    Code:
    #include<iostream.h>
    
    int main()
    
    {
    float number,product;
    cout<<"Enter a number:";
    cin >>number;
    product=number*number;
    
    cout<<number "*"<<number<<"="<<product;
    
    }
    
    Turbo c++ compiler is showing error in a different window!
    
    
     
    Last edited: May 21, 2003
  9. SG-N Registered Senior Member

    Messages:
    1,051
  10. S.Tarafdar Registered Senior Member

    Messages:
    35
    What more can I do?

    AntonK ,SG-N:
    Even it does not work.I am undone!I can not put my entire program here!
     
  11. SG-N Registered Senior Member

    Messages:
    1,051
    Can you e-mail me your program ?
     
  12. S.Tarafdar Registered Senior Member

    Messages:
    35
  13. SG-N Registered Senior Member

    Messages:
    1,051
    Just click on my name and then you will have my details... (e-mail)
     
  14. S.Tarafdar Registered Senior Member

    Messages:
    35
    Your details

    Hi SG-N,
    Thanks.But,I can not send you an e-mail by using the link in your details.I could never do it in any case.
     
  15. SG-N Registered Senior Member

    Messages:
    1,051
    Oops, you're right ! I thought I could do it but I may put an option that don't allow it. Use the e-mail I gave you.
     
  16. AntonK Technomage Registered Senior Member

    Messages:
    1,083
  17. pragmathen 0001 1111 Registered Senior Member

    Messages:
    452
    Hrm...

    #include &lt;conio.h&gt;
    #include &lt;math.h&gt;

    <b>void</b> main(&nbsp; )
    {
    &nbsp;&nbsp;&nbsp;<b>float</b> number, square_value;
    &nbsp;&nbsp;&nbsp;cout << "Enter a number: ";
    &nbsp;&nbsp;&nbsp;cin >> number;
    &nbsp;&nbsp;&nbsp;square_value=number*number;
    &nbsp;&nbsp;&nbsp;cout << "The square of [" << number << "] is [" << square_value << "]";
    &nbsp;&nbsp;&nbsp;getch(&nbsp; );
    }

    I'm not exactly sure about the necessity of including math.h, but perhaps that will help. Anyway the output of the above code should read:

    Enter a number: 2.23
    The square of [2.23] is [4.9729]

    Hope this helps. I'm sure the others could give a helping hand at this as well!
     
Thread Status:
Not open for further replies.

Share This Page