Random Int problem, need help!

I am "coding" a rock paper scissor game (in Swedish because my c++ school book is in Swedish) The book gives me the code and I am supposed to type it down and understand it. But there is errors in the code taken directly from the book. I understand that the problem is about something with the random part. Don't know what to do since my book says this is how it should be.

It's a windows forms, here is the part with the errors on line 233 and 234, it's the same code on line 275, 276, 316 and 317.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  private: System::Void pbxSten_Click(System::Object^  sender, System::EventArgs^  e)
		 {

			Random slump = gcnew Random(); //line 233
			int datornsTal = slump->Next(1, 4); //line 234




			 String^ datornsVal ="";
			 switch ( datornsTal )
			 {
				 case '1':
					 datornsVal = "Sten";
					 break;
				 case '2':
					 datornsVal = "Sax";
					 break;
				 case '3':
					 datornsVal = "Påse";
					 break;
			 }

			 lblDatornsVal->Text = datornsVal;

			 if (datornsVal == "Sax" )
			 {
				nrSpelarVinster++;
			 }
			 else if (datornsVal == "Påse" )
			 {
				nrDatorVinster++;
			 }

			 lblResultat->Text = "Dator: " + nrDatorVinster + " | Spelare: " + nrSpelarVinster;

			 if (nrDatorVinster > 2 || nrSpelarVinster > 2)
			 {
				gbxStenSaxPåse->Enabled = false;
				btnSpela->Enabled = true;
				tbxMinaResultat->AppendText("Dator: " + nrDatorVinster + " | Spelare: " + nrSpelarVinster + "\n");
			 }
		 }

Output:

1>------ Build started: Project: sten sax pase, Configuration: Debug Win32 ------
1>Build started 10/20/2014 15:51:47.
1>InitializeBuildStatus:
1>  Touching "Debug\sten sax pase.unsuccessfulbuild".
1>GenerateTargetFrameworkMonikerAttribute:
1>Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
1>ClCompile:
1>  All outputs are up-to-date.
1>  sten sax pase.cpp
1>c:\users\oskar\documents\visual studio 2010\projects\sten sax pase\sten sax pase\Form1.h(232): error C2664: 'System::Random::Random(int)' : cannot convert parameter 1 from 'System::Random ^' to 'int'
1>          No user-defined-conversion operator available, or
1>          There is no context in which this conversion is possible
1>c:\users\oskar\documents\visual studio 2010\projects\sten sax pase\sten sax pase\Form1.h(233): error C2819: type 'System::Random' does not have an overloaded member 'operator ->'
1>          c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Random'
1>          did you intend to use '.' instead?
1>c:\users\oskar\documents\visual studio 2010\projects\sten sax pase\sten sax pase\Form1.h(233): error C2232: '->System::Random::Next' : left operand has 'class' type, use '.'
1>c:\users\oskar\documents\visual studio 2010\projects\sten sax pase\sten sax pase\Form1.h(275): error C2664: 'System::Random::Random(int)' : cannot convert parameter 1 from 'System::Random ^' to 'int'
1>          No user-defined-conversion operator available, or
1>          There is no context in which this conversion is possible
1>c:\users\oskar\documents\visual studio 2010\projects\sten sax pase\sten sax pase\Form1.h(276): error C2819: type 'System::Random' does not have an overloaded member 'operator ->'
1>          c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Random'
1>          did you intend to use '.' instead?
1>c:\users\oskar\documents\visual studio 2010\projects\sten sax pase\sten sax pase\Form1.h(276): error C2232: '->System::Random::Next' : left operand has 'class' type, use '.'
1>c:\users\oskar\documents\visual studio 2010\projects\sten sax pase\sten sax pase\Form1.h(316): error C2664: 'System::Random::Random(int)' : cannot convert parameter 1 from 'System::Random ^' to 'int'
1>          No user-defined-conversion operator available, or
1>          There is no context in which this conversion is possible
1>c:\users\oskar\documents\visual studio 2010\projects\sten sax pase\sten sax pase\Form1.h(317): error C2819: type 'System::Random' does not have an overloaded member 'operator ->'
1>          c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Random'
1>          did you intend to use '.' instead?
1>c:\users\oskar\documents\visual studio 2010\projects\sten sax pase\sten sax pase\Form1.h(317): error C2232: '->System::Random::Next' : left operand has 'class' type, use '.'
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.48
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

A ^ is required: Random ^slump = gcnew Random(); // Note ^ before slump //line 233
Thanks now it runs, but I think I have some other problem as well because it seems to ignore the code from line 12 to line 33.
Last edited on
datornsTal is an int, so you don't need the single quotes around the numbers 1,2, and 3 in the switch case. The single quotes are used for char values.
Thanks! It's working now.
Topic archived. No new replies allowed.