473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Magic Number !!

Hello every one.
The following is code built by C++ \ CLI . It's built well :
--------------------------------------------------
#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)

{

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!!!

Please, can any person Help??!!

Thanks

===================================
May 10 '07 #1
9 2685
WELCOME ### wrote:
Hello every one.
The following is code built by C++ \ CLI . It's built well :
Please stop posting C++/CLI stuff here, it's *off topic*.

--
Ian Collins.
May 10 '07 #2
Oh
It's C++, and my code problem is C++.
What's wrong..Friend?!!
You can"t fix it?!!!!
======================
"Ian Collins" <ia******@hotmail.comwrote in message
news:5a*************@mid.individual.net...
WELCOME ### wrote:
>Hello every one.
The following is code built by C++ \ CLI . It's built well :

Please stop posting C++/CLI stuff here, it's *off topic*.

--
Ian Collins.

May 10 '07 #3
On May 9, 10:49 pm, "WELCOME ###" <f...@alphalink.com.auwrote:
Oh
It's C++, and my code problem is C++.
What's wrong..Friend?!!
You can"t fix it?!!!!
======================"Ian Collins" <ian-n...@hotmail.comwrote in message

news:5a*************@mid.individual.net...
WELCOME ### wrote:
Hello every one.
The following is code built by C++ \ CLI . It's built well :
Please stop posting C++/CLI stuff here, it's *off topic*.
--
Ian Collins.

It seems you've succumb to one of the top 3 programming errors.

May 10 '07 #4
WELCOME ### wrote:

Please don't top post.
"Ian Collins" <ia******@hotmail.comwrote in message
news:5a*************@mid.individual.net...
>WELCOME ### wrote:
>>Hello every one.
The following is code built by C++ \ CLI . It's built well :
Please stop posting C++/CLI stuff here, it's *off topic*.
Oh
It's C++, and my code problem is C++.
What's wrong..Friend?!!
You can"t fix it?!!!!
======================
The code you posted isn't C++, at least according to my almost but not
quite standard conforming compiler:

CC x.cc
"x.cc", line 1: Error: Could not open include file "stdafx.h".
"x.cc", line 5: Error: System is not defined.
"x.cc", line 7: Warning (Anachronism): Using array as a template without
a declaration.
"x.cc", line 7: Error: System is not defined.
"x.cc", line 7: Error: String is not defined.
"x.cc", line 7: Error: Operand expected instead of ">".
"x.cc", line 7: Error: A class template name was expected instead of array.
"x.cc", line 15: Error: Console is not defined.
"x.cc", line 15: Error: The function "Write" must have a prototype.
"x.cc", line 17: Error: Console is not defined.
"x.cc", line 17: Error: The function "Read" must have a prototype.
"x.cc", line 19: Error: Random is not defined.
"x.cc", line 19: Error: r is not defined.
"x.cc", line 19: Error: gcnew is not defined.
"x.cc", line 19: Error: Badly formed expression.
"x.cc", line 21: Error: r is not defined.
"x.cc", line 29: Error: Console is not defined.
"x.cc", line 29: Error: The function "WriteLine" must have a prototype.
"x.cc", line 37: Error: Console is not defined.
"x.cc", line 37: Error: The function "WriteLine" must have a prototype.
"x.cc", line 41: Error: "}" expected instead of EOF.
20 Error(s) and 1 Warning(s) detected.

--
Ian Collins.
May 10 '07 #5
On Thu, 10 May 2007 12:49:20 +1000 in comp.lang.c++, "WELCOME ###"
<fa***@alphalink.com.auwrote,
>Oh
It's C++, and my code problem is C++.
What's wrong..Friend?!!
You can"t fix it?!!!!
1. Don't top post.
2. "gcnew" and everything that goes with it is not C++.
3. Stop putting assignments in "if" statements.

May 10 '07 #6
On May 10, 2:41 pm, "WELCOME ###" <f...@alphalink.com.auwrote:
>
When you compile this code,it compiles well except if & else.If one operates
the other not!!!

Please, can any person Help??!!
That is how 'if' and 'else' work. Either the first block gets
executed,
or the second block gets executed. Not both. Not none.

May 10 '07 #7
On May 9, 10:41 pm, "WELCOME ###" <f...@alphalink.com.auwrote:
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?
May 10 '07 #8
"Old Wolf" <ol*****@inspire.net.nzwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
On May 10, 2:41 pm, "WELCOME ###" <f...@alphalink.com.auwrote:
>>
When you compile this code,it compiles well except if & else.If one
operates
the other not!!!

Please, can any person Help??!!

That is how 'if' and 'else' work. Either the first block gets
executed,
or the second block gets executed. Not both. Not none.
Well, except in the OP's case the if will always be executed since he's
using = instead of ==
May 10 '07 #9
Jim Langston wrote:
"Old Wolf" <ol*****@inspire.net.nzwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
>On May 10, 2:41 pm, "WELCOME ###" <f...@alphalink.com.auwrote:
>>When you compile this code,it compiles well except if & else.If one
operates
the other not!!!

Please, can any person Help??!!
That is how 'if' and 'else' work. Either the first block gets
executed,
or the second block gets executed. Not both. Not none.

Well, except in the OP's case the if will always be executed since he's
using = instead of ==
I doubt it, not if he tries to compile the code with a C++ compiler....

--
Ian Collins.
May 10 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dave Moore | last post by:
Hi All, Can anybody point me to a FAQ or similar that describes what all this stuff is about please?. I'm interfacing with a MySQL database if that's relavent. I've read a couple of books which...
2
by: stewart.midwinter | last post by:
I've been experimenting with the python zipfile module, and have run into a snag. I'm able to create a new zipfile with the module's ZipFile class and add files to it. After closing the file,...
19
by: youpak2000 | last post by:
Are MAGIC numbers always bad? Using magic numbers (constant numbers) in programs are generally considered a bad programming practice, and it's recommended that to define constants in single,...
0
by: KronicDeth | last post by:
I have a package of python modules deployed on an NFS mount on my network that I use for sysadmin tools. Since some of the machines use different versions of python I've only put the .py files in...
1
by: WELCOME ### | last post by:
Hello every one. The following is code built by C++ \ CLI . It's built well : -------------------------------------------------- #include "stdafx.h" #include <cstdlib> using namespace...
16
by: per9000 | last post by:
Hi, I recently started working a lot more in python than I have done in the past. And I discovered something that totally removed the pretty pink clouds of beautifulness that had surrounded my...
2
by: jyck91 | last post by:
i have done the magic square: #include <stdio.h> #include <stdlib.h> #include <string.h> #define SIZE 13 main() { FILE *fp; int i, j, n, row, column;
4
by: inferi9 | last post by:
Hi, I am working in a program caals magic square and it must be done only with loops and user definied funcations,I will tell you about my code and where my problem, the main is only calls the other...
3
by: Larry Hale | last post by:
Thank you, again, Michael, for all your help many months ago. I *FINALLY* got a HowTo done up; please see http://wiki.python.org/moin/HowTo/FileMagic I've also emailed Mr. Hupp to see if he'll...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.