Can you fix this code?

W

WELCOME ###

#include "stdafx.h"

#include "cstdlib"

using namespace System;

int main(array<System::String ^> ^args)

{


int magic;

int guess ;

magic = rand();

magic=7;

Console::Write(L" Enter your Guess Number : ");

guess=Console::Read();


if(guess == magic)

Console::WriteLine( L"Bravo");


else

Console::WriteLine(L"SORRY");


return 0;

}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
J

Jim Langston

WELCOME ### said:
#include "stdafx.h"

#include "cstdlib"

using namespace System;

int main(array<System::String ^> ^args)

{


int magic;

int guess ;

magic = rand();

magic=7;

Console::Write(L" Enter your Guess Number : ");

guess=Console::Read();


if(guess == magic)

Console::WriteLine( L"Bravo");


else

Console::WriteLine(L"SORRY");


return 0;

}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

May have sytnax errors (not tested)

#include <iostream>
int main()
{
int magic;

// magic = rand();

magic=7;

std::cout << "Enter your guess number: ";

int guess ;
if ( std::cin >> guess )
if (guess == magic)
std::cout << "\nBravo\n";
else
std::cout << "\nSORRY\n";

return 0;

}
 
P

pmouse

#include "stdafx.h"

#include "cstdlib"

using namespace System;

int main(array<System::String ^> ^args)

{

int magic;

int guess ;

magic = rand();

magic=7;

Console::Write(L" Enter your Guess Number : ");

guess=Console::Read();

if(guess == magic)

Console::WriteLine( L"Bravo");

else

Console::WriteLine(L"SORRY");

return 0;

}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

This looks like c++/cli to me. So instead of rand(), use Random^ r =
gcnew Random(); and r->Next();

and make sure your compiler supports CLI, and the options is turned
on.

Regards,

PQ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top