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

In summary: As the warning indicates, your program is attempting to use variables--y and sum-- that haven't been properly initialized.
  • #1
tj00343
63
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. thanks in advance to anyone who answers
Btw. the compiler I'm using is Borland C++ 5.0
 
Physics news on Phys.org
  • #2
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
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.
 

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

1. Why is my program giving me errors when I try to compile it?

There could be several reasons for this, such as syntax errors, missing libraries, or incorrect data types. Check your code for any typos or missing semicolons, and make sure you have included the necessary libraries for your program to run successfully.

2. How do I fix a segmentation fault in my program?

A segmentation fault occurs when a program tries to access memory that it does not have permission to access. This can happen due to a variety of reasons, such as a null pointer or an out-of-bounds array. Use a debugger or print statements to identify the specific line of code causing the segmentation fault and then fix the issue.

3. I am getting a "no matching function" error. What does this mean?

This error means that the compiler cannot find a function with the specified name and parameters in your code. Check your function declarations and calls to make sure they match, including the data types of the parameters.

4. How do I use pointers in my Borland C++ program?

To use pointers in Borland C++, you need to declare a pointer variable using the * symbol, assign it a memory address using the & symbol, and dereference it using the * symbol. It is important to handle pointers carefully to avoid memory leaks and segmentation faults.

5. How do I read and write to files in Borland C++?

To read and write to files in Borland C++, you can use the fstream library. Use the open() function to open a file, the getline() function to read from the file, and the write() function to write to the file. Don't forget to close the file using the close() function when you are finished.

Similar threads

Replies
3
Views
899
Replies
2
Views
2K
Replies
8
Views
1K
Replies
15
Views
2K
Replies
3
Views
1K
Replies
5
Views
2K
Replies
23
Views
2K
Back
Top