Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: how to finsh this C++ program

  1. #1
    Join Date
    Jan 2005
    Posts
    263
    Country
    United States

    Default how to finsh this C++ program

    Can any one help me with this C++ program. C++ program to receive two integers from the keyboard. The program should display the sum, product and difference of the two (2) numbers. I have write this so far and I am lost now can you help me with it?

    #include <iostream.h>

    int main()
    {
    double num1;
    double num2;
    double sum;
    double prod;
    double diff;
    double quot;

    cout<<"Enter a number: ";
    cin>>num1;

    cout<<"Enter a next number: \n";
    cin>>num2;

    sum = num1 + num2;

    prod = num1 / num2;

    diff = num1 - num2;

    quot = num1 * num2;




    return 0;

    }

  2. #2
    Join Date
    Jun 2004
    Posts
    3,552

    Default Re: how to finsh this C++ program

    cout << "the sums is " << sum << endl;
    cout << "the product is " << prod << endl;
    cout << "the difference is " << diff << endl;

    you want to put that in after you've gotten the intergers and done with the calculations.
    secondly, shouldn't you be entering using std::cout and so forth??

    cout<<"Enter a number: ";
    cin>>num1;
    you didn't give this a new line, just pointing it out.

  3. #3
    Join Date
    Nov 2002
    Posts
    2,239
    Country
    Jamaica

    Default Re: how to finsh this C++ program

    #include <iostream.h>

    int main()
    {
    double num1;
    double num2;
    double sum;
    double prod;
    double diff;
    double quot;

    cout<<"Enter a number: ";
    cin>>num1;

    cout<<"Enter a next number: \n";
    cin>>num2;

    sum = num1 + num2;

    prod = num1 / num2;

    diff = num1 - num2;

    quot = num1 * num2;

    <b>
    printf (%d, Sum \n)
    printf (%d, prod \n)
    printf (%d, diff \n)
    printf (%d, quot \n)
    </b>

    return 0;

    }

    I think thats about all thats left to do
    Last edited by Skillachi; February 1, 2005 at 09:12 AM.
    Laptop: HP DV6700t - Core 2 Duo T9300 2.5Ghz, 3GB RAM, Nvidia 8400m GS, 250GB HDD. Ubuntu 12.04 and Windows 7
    Phone: Samsung Galaxy Nexus

  4. #4
    Join Date
    Nov 2002
    Posts
    2,239
    Country
    Jamaica

    Default Re: how to finsh this C++ program

    Whoops... been doing C instead of C++
    Laptop: HP DV6700t - Core 2 Duo T9300 2.5Ghz, 3GB RAM, Nvidia 8400m GS, 250GB HDD. Ubuntu 12.04 and Windows 7
    Phone: Samsung Galaxy Nexus

  5. #5
    Join Date
    Jun 2004
    Posts
    3,552

    Default Re: how to finsh this C++ program

    well if shane is familiar with the printf method in c++ he should still be fine skillachi.

  6. #6
    Join Date
    Apr 2004
    Posts
    4,826
    Country
    Jamaica

    Default Re: how to finsh this C++ program

    Ahh the good old days.... C++. It looks okay to me, you just not echoing the results.

    Quote Originally Posted by digitalchef
    you didn't give this a new line, just pointing it out.
    Why do you need to give it a new line? Its not necessary
    Last edited by Virus; February 1, 2005 at 09:48 AM.

  7. #7
    Join Date
    Jan 2004
    Posts
    2,015
    Country
    Jamaica

    Default Re: how to finsh this C++ program

    virus the new line is necessary for reada bility still, the results would be cluttered. and c++ good old days for you ........ ez virii.

  8. #8
    Join Date
    Jan 2005
    Posts
    263
    Country
    United States

    Default Re: how to finsh this C++ program

    Thxxx alot. I c what I was doing worng.

  9. #9
    Join Date
    Apr 2004
    Posts
    4,826
    Country
    Jamaica

    Default Re: how to finsh this C++ program

    Print the results....... u would could a new line for readability. Chef was pointing out something else.

  10. #10
    Join Date
    Mar 2004
    Posts
    774
    Country
    Jamaica

    Default Re: how to finsh this C++ program

    i think you ned to use std::cout or put in the heading 'using stdlib' or u will get runtime errors
    Nickname: Virus
    Occupation: Software Engineer
    Education: B.Sc. Computer Information Science, Asc. Mass Communication, MCSD, MCSE and CCNA

Posting Permissions

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