CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Beginner in C++

  1. #1
    Join Date
    Jan 2003
    Posts
    15

    Beginner in C++

    Hi

    I have written the progam below.Its very basic.
    I am getting the output 2 but i expect to get 2.5

    Can any one help


    -----------------------------------------------------
    #include <iostream>

    int main()
    {

    double input = 0.00; // no of sequences

    input = 5 / 2;

    cout << " Output " << input << endl;

    }

    --------------------------------------------------------

  2. #2
    Join Date
    Oct 2002
    Location
    Arkansas, USA
    Posts
    189
    input = 5 / 2;
    The most likely cause of what you see is that you are doing a division of ints and assigning the value to a double after the division is done. Try
    Code:
    input = 5.0/2.0
    Last edited by gjs368; January 28th, 2003 at 10:27 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured