English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I keep getting an eroor message. The error message is error C2065: 'endl' : undeclared identifier



#include
#include

using std::cout;
using std::cin;

int main()
{
int num1, num2, Multiple;

cout << "Enter two numbers and i will tell u if the\n";
cout << "first is a multiple of the second number:\n";

cin >> num1 >> num2;

Multiple = num2 % num1;

if (Multiple == 0)
cout << "\nThe first number is a multiple of the second.\n\n";

if (Multiple != 0)
cout << "\nThe first number is not a multiple of the second.\n\n";
return 0;
}

2007-10-07 11:07:17 · 6 answers · asked by Anonymous in Computers & Internet Programming & Design

I am still getting the error C2065: 'endl' : undeclared identifier

2007-10-07 11:34:30 · update #1

6 answers

Now I'm not getting paid $100+ per hour to do this, so I didn't bother to even check if your code actually does what you think it does - so maybe GIGO if you have other 'bugs'!

You didn't say WHAT compiler, so I will have to just use general problem solving principles based on about 30 years bloody minded experience with about 30+ languages in many different 'language families'!

Now it doesn't really matter WHAT language you are compiling, the basic principles are ALWAYS the same.

Without knowing just exactly what the compiler is doing internally, let us just assume that is chewing the input, looking for tokens/chunks it recognises so it can digest them.

Now a general "if statement" (irrespective of language - of this sort of computing language family - of course!) has the following generic layout:

[code block A]
If {condition} then
[code block 'then']
else
[code block 'else']
endif
[code block B]

Code blocks A & B are external to the if statement and both are always executed.

You should clearly understand the flow thru the if statement:
either the 'then block' or the 'else block' is executed. If there is no 'else block', then that is of course ignored, and execution either does the 'then block' or does not do it, and then execution always resumes at code block B. Code block B would normally be something of the order 'variable is assigned to be some value'.

Now your coding has 'implied' (not explicit) 'then', 'else' and 'end if' statements.

What is worse, it is not clear whether you want both if statements to be always executed in sequence, or if the 2nd if statement is intended to be 'nested' inside the first if block.

God knows WHAT the compiler really thinks, since you didn't say which one it is... but at a guess, it seems the compiler's default action is to look at the 'variable table' before it consults the 'list of reserved words'...
when it hits the 'return' statement (while it is still trying to digest the 'if statement' block and looking for an 'endif' statement!) in an implied nested 'if then if' statement, it encounters what it thinks is an undeclared variable (called 'return' - which you did not declare!) to be part of a {'variable is assigned to be some value' token/chunk} - hence the error message! :-)

Just bunging a pile of assorted crap into the compiler and saying like a certain Medieval Bishop (who said "kill them all - let God sort them out!" when asked how to sort the Christians from the infidels) 'let the compiler sort it out!' is no substitute for clearly understanding the language and code flow within it, and ensuring that you write explicit code, instead of writing implicit code and ***-U-MEing that the compiler will understand 'what you thought you meant'!

Glad to be of help!
(IQ SD +5)
:-P

2007-10-07 23:56:14 · answer #1 · answered by fooles.troupe 7 · 5 0

Try this code
#include

int main()
{
int num1, num2, Multiple;

cout << "Enter two numbers and i will tell u if the\n";
cout << "first is a multiple of the second number:\n";

cin >> num1;
cin >> num2;

Multiple = num2 % num1;

if (Multiple == 0)
cout << "\nThe first number is a multiple of the second.\n\n";

if (Multiple != 0)
cout << "\nThe first number is not a multiple of the second.\n\n";
return 0;
}

2007-10-07 11:18:34 · answer #2 · answered by Andy T 7 · 0 1

hello,
all you need to do is make:

Multiple = num1 % num2;

and it will work :))
------------------
so ur program will become:
-------------------------------------------

#include
#include

using std::cout;
using std::cin;

int main()
{
int num1, num2, Multiple;

cout << "Enter two numbers and i will tell u if the\n";
cout << "first is a multiple of the second number:\n";

cin >> num1 >> num2;

Multiple = num1 % num2;

if (Multiple == 0)
cout << "\nThe first number is a multiple of the second.\n\n";

if (Multiple != 0)
cout << "\nThe first number is not a multiple of the second.\n\n";
return 0;
}

------------------
hope I helped

2007-10-07 11:20:17 · answer #3 · answered by Anonymous · 0 1

I see no problems with the code you've posted... I even compiled it myself thinking I missed it.

2007-10-07 11:20:27 · answer #4 · answered by gitter1226 5 · 0 1

save the program close it
reopen it and cmpile
it must work

2007-10-07 18:45:02 · answer #5 · answered by i_am_the_next_best_one 5 · 0 1

include file problem instead of you have write

2016-05-18 02:31:41 · answer #6 · answered by ? 3 · 0 0

fedest.com, questions and answers