Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Borland C++ programming quistion, what's wrong with my program

  1. Mar 9, 2010 #1
    This program is supposed to add 2 integers ,according to the compiler, there are 2 warnings and 1 error ,the error is (undefined symbol' end')
    the warnings are 'sum' and 'y' are declared but never used

    here is the program :

    # include <iostream>
    # include <conio.h>
    intmain()
    {
    int x;
    int y;
    int sum;
    cout<< "enter 2 integers " ;
    cin>>x ;//read an integer and store it in sum x+y ; x
    cout<<"the sum of" <<x<< "and" <<y<< "is" <<sum<< end;
    getch();
    return 0;
    }

    What's wrong with it. thanx in advance to anyone who answers
    Btw. the compiler I'm using is Borland C++ 5.0
     
  2. jcsd
  3. Mar 9, 2010 #2

    Borek

    User Avatar

    Staff: Mentor

    Warnings are a little bit off IMHO, but error is obvious.

    'end' is not defined (hint: check documentation what is the correct name you should be using, you want to end line).

    y & sum are declared and used - but at he moment of their use programs has no chances of knowing what their values are.
     
  4. Mar 9, 2010 #3

    Mark44

    Staff: Mentor

    line 3: "intmain" function
    line 9: You have commented out what you evidently mean to be executable code.
    line 9: Your comment exhibits faulty thinking. You can't read in a value and store it in an expression. You can only store a value in a variable. x + y is not a variable.
    line 10: As the warning indicates, your program is attempting to use variables--y and sum-- that haven't been properly initialized. What will be displayed will be "garbage" values.
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook