0% found this document useful (0 votes)
83 views3 pages

Program: Using Using Using Using Namespace Class

This document contains code for a slot machine program written in C#. It initializes credits to 50 and displays a welcome message. It then generates random numbers to determine slot outcomes and checks if combinations like 3 bananas, apples, etc. are matched to award credits. If not matched, it indicates a bust. It reads keyboard input and continues the loop while credits remain.

Uploaded by

Diana Iagar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views3 pages

Program: Using Using Using Using Namespace Class

This document contains code for a slot machine program written in C#. It initializes credits to 50 and displays a welcome message. It then generates random numbers to determine slot outcomes and checks if combinations like 3 bananas, apples, etc. are matched to award credits. If not matched, it indicates a bust. It reads keyboard input and continues the loop while credits remain.

Uploaded by

Diana Iagar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 3

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SlotMachine
{
class Program
{

static void Main(string[] args)


{
Random randNumGen = new Random();
int credits = 50;

Console.WriteLine("******************************************");
Console.WriteLine("------------------------------------------");
Console.WriteLine("Welcome to SILVIA-DIANA's Slot Machine!");
Console.WriteLine("------------------------------------------");
Console.WriteLine("Press Spacebar to Roll the slot machine!");
Console.WriteLine("------------------------------------------");
Console.WriteLine("-------Credits Available: " + credits + "--------------");
Console.WriteLine("******************************************");

ConsoleKeyInfo keyInfo = Console.ReadKey(true);

while (credits > 0)


{

Console.WriteLine("******************************************");
Console.WriteLine("---££----Credits Available: " + credits + "-----£
£-----");
Console.WriteLine("******************************************");

if (keyInfo.Key == ConsoleKey.Spacebar)
{
credits--;
string slot1;
string slot2;
string slot3;

int randNum1 = randNumGen.Next(10000, 20000);


int randNum2 = randNumGen.Next(30000, 40000);
int randNum3 = randNumGen.Next(50000, 60000);

Console.WriteLine("First Random Number: " + randNum1);


Console.WriteLine("Second Random Number: " + randNum2);
Console.WriteLine("Third Random Number: " + randNum3);

int modR1 = randNum1 % 32;


int modR2 = randNum2 % 32;
int modR3 = randNum3 % 32;

Console.WriteLine("------------------------------------------");
Console.WriteLine("1st Remainder Left over: " + modR1);
Console.WriteLine("2nd Remainder Left over: " + modR2);
Console.WriteLine("3rd Remainder Left over: " + modR3);
Console.WriteLine("------------------------------------------");

string[] slots = new string[32];

for (int i = 0; i < 8; i++)


slots[i] = "BANANA";
for (int i = 8; i < 15; i++)
slots[i] = "APPLE";
for (int i = 15; i < 21; i++)
slots[i] = "CHERRY";
for (int i = 21; i < 26; i++)
slots[i] = "BELL";
for (int i = 26; i < 30; i++)
slots[i] = "ROSE";
for (int i = 30; i < 32; i++)
slots[i] = "Lucky 7";

slot1 = slots[modR1];
slot2 = slots[modR2];
slot3 = slots[modR3];

Console.WriteLine("Slot 1: " + slot1);


Console.WriteLine("Slot 2: " + slot2);
Console.WriteLine("Slot 3: " + slot3);
if ((slot1 == "BANANA") && (slot2 == "BANANA") && (slot3 ==
"BANANA"))
{
credits = credits + 5;
Console.WriteLine("YOU WIN!! ££££££££ 3 CREDITS ££££££££");
}

else if ((slot1 == "APPLE") && (slot2 == "APPLE") && (slot3 ==


"APLE"))
{
credits = credits + 10;

Console.WriteLine("YOU WIN!! ££££££££ 6 CREDITS ££££££££");


}

else if ((slot1 == “CHERRY") && (slot2 == "CHERRY") && (slot3 ==


"CHERRY"))
{

credits = credits + 15;

Console.WriteLine("YOU WIN!! ££££££££ 10 CREDITS ££££££££");


}

else if ((slot1 == "BELL") && (slot2 == "BELL") && (slot3 == "BELL"))


{
credits = credits + 20;

Console.WriteLine("YOU WIN!! ££££££££ 20 CREDITS ££££££££");


}

else if ((slot1 == "ROSE") && (slot2 == "ROSE") && (slot3 == "ROSE"))


{
credits = credits + 40;

Console.WriteLine("YOU WIN!! ££££££££ 40 CREDITS ££££££££");


}

else if ((slot1 == "LUCKY 7") && (slot2 == "LUCKY 7") && (slot3 ==
"LUCKY 7"))
{

credits = credits + 100;

Console.WriteLine("JACKPOT!! ££££££££ 100 CREDITS ££££££££");


}

else
{

Console.WriteLine("BUST!! ##### NO CREDITS ######");


}

keyInfo = Console.ReadKey(true);

else
{
Console.WriteLine("WRONG KEY!... Press Spacebar");
keyInfo = Console.ReadKey(true);
}
}
}
}
}

You might also like