Question:
Can U tell me what is wrong witht his program using C++..?
anonymous
2007-10-07 15:07:17 UTC
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;
}
Six answers:
fooles.troupe
2007-10-08 03:56:14 UTC
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
Andy T
2007-10-07 15:18:34 UTC
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;

}
anonymous
2007-10-07 15:20:17 UTC
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
gitter1226
2007-10-07 15:20:27 UTC
I see no problems with the code you've posted... I even compiled it myself thinking I missed it.
i_am_the_next_best_one
2007-10-07 22:45:02 UTC
save the program close it

reopen it and cmpile

it must work
?
2016-05-18 06:31:41 UTC
include file problem instead of you have write


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...