Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

rob64464

10 Random Numbers (C#)

This topic is 5384 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is what I want to do basically create a slot machine. I have writen what operations I want to do. Would anybody be so kind to translate this to the c# language? Generate 5 random numbers if number = 1 then print on screen "bar" if number = 2 then print on screen "apple" if number = 3 then print on screen "cherry" if number = 4 then print on screen "grapes" if number = 5 then print on screen "lemon" Thanks again, Robert

Share this post


Link to post
Share on other sites
Advertisement
Random rnd = new Random();
for (int i=0; i<5; i++) {

int number = rnd.Next(5) + 1;
switch (number) {
case 1:
Console.WriteLine("bar");
break;
case 2:
Console.WriteLine("apple");
break;
case 3:
Console.WriteLine("cherry");
break;
case 4:
Console.WriteLine("grapes");
break;
case 5:
Console.WriteLine("lemon");
break;

}
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thank you this really has helped me :-)

Rob

Share this post


Link to post
Share on other sites
How would i add a basic add up code?

[STAThread]
static void Main(string[] args)
{
Random rnd = new Random();
for (int i=0; i<3; i++) // going to print a total of 3 items
{

int number = rnd.Next(5) + 1; //go through all 5 cases
switch (number)
{
case 1: // if the number = case 1 then print ''BAR''
Console.WriteLine("BAR");
break;
case 2: // if the number = case 2 then print ''APPPLE''
Console.WriteLine("APPLE");
break;
case 3: // if the number = case 3 then print ''CHERRY''
Console.WriteLine("CHERRY");
break;
case 4: // if the number = case 4 then print ''GRAPES''
Console.WriteLine("GRAPES");
break;
case 5: // if the number = case 5 then print ''LEMON''
Console.WriteLine("LEMON");
break;

}
}

{
// Check to see if the user has won anything!


}

thank you,
rob

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
"How would i add a basic add up code?"

What do you mean?

"int number = rnd.Next(5) + 1;"

int number = rnd.Next(1, 6);

Share this post


Link to post
Share on other sites
This is c code, i suppose it also works in c# as is:


const int cherry = 4; //or some other number :)

if ((slots[0]==cherry) && (slots[1]==cherry) && (slots[2]==cherry))
Score += 20;




[edited by - Nik02 on September 25, 2003 9:39:42 AM]

Share this post


Link to post
Share on other sites
Meh, best way:

enum Slots {Bar, Cherry, Apple, Grapes, Lemon};
Random rand = new Random();

for (int i = 0; i < 5; i++)
Console.Out.WriteLine("{0}",(Slots)rand.Next(4));

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!