Results 1 to 7 of 7

Thread: My first program! Is it correct? My school's c++ software is still being configured.

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    7

    My first program! Is it correct? My school's c++ software is still being configured.

    Here it is...

    #include <iostream.h>

    int main ()

    {

    int n1, n2

    cout<<"Enter the number:";
    cin>>n1;
    cout<<"Enter the second number:";
    cin>>n2;

    // sum
    int sum
    sum=n1+n2;

    //product
    int product
    product = n1 * n2;

    //differance
    int differance
    differance = n1\n2;

    //output
    cout<< "The sum of these numbers are:";
    cout<< sum;
    cout<< "The diff of these numbers are:";
    cout<< differance;
    cout<< "The product of these numbers are:";
    cout<< product;

    return 0;

    }

    So how wrong is my program? My school sucks so much that I have to write my programs on a friggen piece of paper.
    Search message boards with MessageKing

  2. #2
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    it looks good, except you forgot the ; after variable declarations
    Amon Ra
    The Power of Learning.

  3. #3
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    It is OK, but maybe for school the main function should be
    Code:
    main( int argc, char *argv[ ], char *envp[ ] )
    {
    program-statements
    }
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  4. #4
    Zaei
    Guest
    Why do that Vlatko? Very likely, he wont need the command line, and I doubt he will EVER need the environ strings.

    Also, you tried doing difference with the vb integer division operator. The statement should (probably) be:
    Code:
    //quotient
    int quotient
    quotient = n1/n2;
    
     or...
    
    //quotient
    double quotient // most schools like doubles  o.O
    quotient = double(n1)/n2;
    Z.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Vlatko, he probably won't have VC++ at school and envp is Microsoft specific.

    warrior, you should also add endl (end line) to your couts, or else it will all be one long line...
    Code:
    cout<< "The sum of these numbers are:"; 
    cout<< sum << endl;
    etc.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Well, i know that it is not likely that he will need the command line in apps like this, but i suggested that beacuse i know teachers must teach everything by the rules and many say that the main function should always be with argv and argc regardless of their need in the current app.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Also, iostream.h is deprecated. Use:
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char **argv) {
        // Statements
    
        return 0;
    }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

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