Re: Magic Number !!
On May 9, 10:41 pm, "WELCOME ###" <f...@alphalink.com.au> wrote:
Hello every one.
The following is code built by C++ \ CLI . It's built well :
i don't think so.
--------------------------------------------------
#include "stdafx.h"
#include <cstdlib>
using namespace System;
int main(array<System::String ^> ^args)
{
int magic;
int guess;
Console::Write(L"Enter Your Guess Number : ");
guess=Console::Read();
Random^ r = gcnew Random();
r->Next();
magic=7;
if(guess=7)
Uh, the above statement says:
if you successfully *assign* the literal value 7 to the variable
guess, then process the accompanying block.
Its a *assignment*, not a comparison
Try:
if ( 7 == guess ) // ah, not an assignment
{
...
}
I placed the constant on the left side for a reason, at least that way
if you mistakenly write (7 = guess) the compiler will generate an
obvious error since the lhv is a constant.
Let that be a lesson to you.
{
Console::WriteLine(L"BRAVO");
}
else
{
Console::WriteLine(L" SORRY..");
}
return 0;
--------------------------------------
When you compile this code,it compiles well except if & else.If one operates
the other not!!!
thats expected, see above.
Next time, can you please post C++ code?