• Support PF! Buy your school textbooks, materials and every day products Here!

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

  • Comp Sci
  • Thread starter tj00343
  • Start date
  • #1
60
0
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
 

Answers and Replies

  • #2
Borek
Mentor
28,327
2,714
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.
 
  • #3
33,170
4,857
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 :
Code:
# 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
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.
 

Related Threads for: Borland C++ programming quistion, what's wrong with my program

Replies
6
Views
784
Replies
2
Views
2K
  • Last Post
Replies
3
Views
1K
Replies
2
Views
10K
Replies
3
Views
889
  • Last Post
Replies
5
Views
4K
  • Last Post
Replies
9
Views
1K
Top