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

Click For Summary
SUMMARY

The forum discussion addresses a programming error in a Borland C++ 5.0 application intended to add two integers. The primary error is an "undefined symbol 'end'" due to a typo; the correct term is "endl" for line termination. Additionally, the warnings about 'sum' and 'y' being declared but never used stem from improper initialization and usage of these variables. The program fails to read the second integer 'y' and compute the sum correctly, leading to the display of uninitialized values.

PREREQUISITES
  • Understanding of C++ syntax and structure
  • Familiarity with the Borland C++ 5.0 compiler
  • Knowledge of variable initialization and usage in C++
  • Basic understanding of input/output operations in C++ using cin and cout
NEXT STEPS
  • Review C++ variable initialization and scope
  • Learn about C++ input/output operations, specifically cin and cout
  • Study the correct usage of stream manipulators like endl
  • Explore debugging techniques in Borland C++ 5.0 to identify and resolve compilation errors
USEFUL FOR

Beginner and intermediate C++ programmers, particularly those using Borland C++ 5.0, who are looking to troubleshoot common programming errors and improve their understanding of variable management and input/output operations.

tj00343
Messages
59
Reaction score
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;
count<< "enter 2 integers " ;
cin>>x ;//read an integer and store it in sum x+y ; x
count<<"the sum of" <<x<< "and" <<y<< "is" <<sum<< end;
getch();
return 0;
}

What's wrong with it. thanks in advance to anyone who answers
Btw. the compiler I'm using is Borland C++ 5.0
 
Physics news on Phys.org
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.
 
tj00343 said:
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. thanks 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.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 23 ·
Replies
23
Views
9K
  • · Replies 24 ·
Replies
24
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 23 ·
Replies
23
Views
3K