I need help with this problem, ok so I am making a program for my brother that randomizes 2 things, a Number(1-6) and a Letter(A-E), I go for the randomize 2 numbers, one for the number, and one for the letter. So i was going very well, until I compile it for the final blow, when It comes up with this error:

error C2450: switch expression of type 'System::Random ^' is illegal
No user-defined-conversion operator available, or
Integral expression required

Here is the segment of code it was in, the bold is the line the error is in.

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                 label1->Text = ( (int^)randNumGen2->Next(1,5) )->ToString();
                 label2->Text = ( (int^)randNumGen->Next(1,7) )->ToString();
                 [B]switch (randNumGen2)[/B]
                 {
                 case 1: label1->Text = "A";
                     break;
                     case 2: label1->Text = "B";
                         break;
                         case 3: label1->Text = "C";
                             break;
                             case 4: label1->Text = "D";
                                 break;
                                 case 5: label1->Text = "e";
                                     break;
                 }

             }

Please help.

Recommended Answers

All 4 Replies

Yea, I defintaly don't get that.

switch (randNumGen2) randNumGen2 is not an integral expression and can not be used in a switch.
did you intend switch[B][B]( [/B][/B]randNumGen2->Next(1,5)[B][B] )[/B][/B] ?

switch (randNumGen2)
randNumGen2 is not an integral expression and can not be used in a switch.
did you intend switch( randNumGen2->Next(1,5) ) ?

hmm.. thats sounds right, i just need to define that its a integer with

->Next(1,5)

..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.