Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

BRACKEYS - Solution to C# Tutorial 04 Challenge

• Member

these is mine

using System;

namespace My_awesome_program

{

class Program

{

static void Main(string[] args)

{

Random numberGen = new Random();

int r1 , r2;

r1 = 0;

r2 = 1;

int atpts = 0;

Console.WriteLine("Press enter to roll a die: ");

while (r1 != r2) {

r1 = numberGen.Next(1, 7);

r2 = numberGen.Next(1, 7);

Console.WriteLine("Dice 1: "+ r1);

Console.WriteLine("Dice 2: "+ r2 +"\n");

atpts++;

}

Console.WriteLine("It took you "+ atpts + " attempts to roll two of a kind.");

}

}

}

• Member

using System;

namespace MyAwesomeMathQuiz

{

class Program

{

static void Main(string[] args)

{

Random numberGen = new Random();

int roll1 = 0;

int roll2 = 1;

int attempts = 0;

Console.WriteLine("Press any key to roll both dices.");

while(roll1 != roll2) {

roll1 = numberGen.Next(1, 7);

roll2 = numberGen.Next(1, 7);

Console.WriteLine("You rolled : " + roll1 + " and " + roll2);

attempts++;

}

Console.WriteLine("It took u " + attempts + (" attempts to roll same numbers!"));

}

}

}

• Member

I tried as well :D

using System;

namespace Best_Program

{

class Program

{

static void Main(string[] args)

{

Random numberGen = new Random();

int roll01 = 0;

int roll02 = 0;

int attemts = 0;

Console.WriteLine("Press enter to roll the die!");

while (roll01 != 6 || roll02 != 6)

{

roll01 = numberGen.Next(1,7);

Console.WriteLine("Your first die rolled " + roll01);

roll02 = numberGen.Next(1,7);

Console.WriteLine("Your second die rolled " + roll02);

attemts++;

}

Console.WriteLine("It took you " + attemts + " attemts!");

}

}

}

• Member

I tried too ended up good.

using System;

namespace Program

{

class Program

{

static void Main(string[] args)

{

//Program Title:

Console.Title = "Two of a Kind";

//Program Width:

Console.WindowWidth = 150;

//Font Color:

Console.ForegroundColor = ConsoleColor.Yellow;

//Content:

Random numberGen = new Random();

int dice1 = 0;

int dice2 = 1;

int attempts = 0;

//Gameplay:

Console.WriteLine("Welcome to Two of a Kind. This is a game of chance where you will have to roll two dice.");

Console.WriteLine("If you get two if the same dice within 4 attempts, you win and will be rewarded with 100 lives.");

Console.ForegroundColor = ConsoleColor.Red;

Console.WriteLine("But if you don't, you will lose the number of lives equal to the attempts that you have made.");

Console.WriteLine("GOODLUCK :)");

Console.ForegroundColor = ConsoleColor.Yellow;

while (dice1 != dice2)

{

dice1 = numberGen.Next(1, 7);

dice2 = numberGen.Next(1, 7);

Console.WriteLine("You rolled: " + dice1);

Console.WriteLine("You rolled: "+ dice2 + "\n");

attempts++;

}

Console.WriteLine("Press ENTER to know the number of you attempts...");

Console.WriteLine("You have made " + attempts + " attempts...");

if (attempts <= 4)

{

Console.WriteLine("You have passed. Receive the blessing of IMMORTALITY!");

} else

{

Console.ForegroundColor = ConsoleColor.Red;

Console.WriteLine("You have failed mortal. RECEIVE THE PUNISHMENT FOR THE WICKED!!!");

}

//Ending Sequence:

Console.WriteLine("Press ENTER to know the next judgement.....");

}

}

}

• Member

love this series of tutoriasl and it's really helping me to acomplish my goal of learning to code at least a bit!!

so i made my version and had no problem doing my two dices program and the i tried to make it like a trow dice against the computer but for some reason i still can't make it work. help!!!

Console.WriteLine("Ok " + name + " Let's play Dice!!");

Console.WriteLine("First you roll and then I roll, Wins the bigger number every turn");

Random numberGen = new Random();

int roll1 = 0;

int roll2 = 1;

if ( roll1 == roll2){

Console.WriteLine("Nice tie, let's do it again!!");

}

while (roll1 < roll2)

{

roll1 = numberGen.Next(1, 7);

roll2 = numberGen.Next(1, 7);

Console.WriteLine("You rolled: " + roll1 + " I rolled: " + roll2 );

Console.WriteLine(" I win, Let's go again");

Console.WriteLine(" PRESS ENTER");

}

Console.WriteLine("You rolled: " + roll1 + " I rolled: " + roll2 );

Console.WriteLine ("YOU WIN!!!");

• Member

I don't understand why you set roll2 to 1

• Member

Victor me too idk why

@Victor16

• Member

somebody explained it to me

It's because when you tried to enter into the while loop they would both be 0 therefore (role1 != role2) would be false and the loop would never start.

@GostGK_YT

• Member
• Member

Oh, I made it exactly by my own :)

• Member

Added a small if statement so it doesn't say "it took you 1 attempts" :)

• Member

I was getting the same number rolled for both dice, so I made a new variable for a new Random() numberGen and was able to get the dice to roll different numbers.

using System;

namespace c__Programs

{

class Program

{

static void Main(string[] args)

{

Random numberGen = new Random();

Random nr = new Random();

int roll = 0;

int roll2 = 1;

int attempts = 0;

Console.WriteLine("Press enter to roll the dice");

while(roll != roll2) {

roll = numberGen.Next(1,7);

roll2 = nr.Next(1, 7);

Console.WriteLine("Rolled: " + roll);

Console.WriteLine("Rolled: " + roll2 + "\n");

attempts++;

}

Console.WriteLine("It took you " + attempts + " to roll a pair.");

//Write before closing the program.

}

}

}

• Member

here is my version because Brackeys' version didn't work for me. after a lot of fideling around it finally works and i don't know why.

class Program

{

static void Main(string[] args)

{

Random numberGen = new Random();

int roll1 = 0;

int roll2 = 0;

int attempts = 0;

Console.WriteLine("press enter to roll the dies");

while (true)

{

roll1 = numberGen.Next(1, 7);

roll2 = numberGen.Next(1, 7);

Console.WriteLine("Roll 1: " + roll1);

Console.WriteLine("Roll 2: " + roll2 + "\n");

attempts++;

if (roll1 == roll2)

{

Console.WriteLine("you rolled two of a kind");

Console.WriteLine("It took you " + attempts + " attempts");

break;

}

}

//wait before closing

}

}

• Member

My solution (changed it up a little bit).

```using System;
using System.Collections.Generic;

namespace yes_man
{

class program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Title = "this is a stupid program";

Random theNumber = new Random();

int roll = 1;
int roll2 = 2;
int attempts = 5;

Console.WriteLine("Click enter to roll 2 dice. To win, get the same number on both rolls (1-5). You have 5 attempts.");

while(attempts > 0 && roll != roll2)
{

attempts--;
roll = theNumber.Next(1, 6);
roll2 = theNumber.Next(1, 6);

Console.WriteLine("Roll 1: " + roll);
Console.WriteLine("\nRoll 2: " + roll2);
Console.WriteLine("\nYou have " + attempts + " attempts left.\n\n");

}
if(roll == roll2 && attempts > 0)
{
Console.WriteLine("Congrats! You won!");

} else if(roll != roll2 && attempts == 0)
{
Console.WriteLine("You lost! Reopen this program to try again.");
}

}
}
}
```
• Member
edited March 2021

using System;

namespace my_awsome_program

{

class Program

{

static void Main(string[] args)

{

//In this program you can enter the maximum number of times you want to try for 'two of a kind'

Console.WriteLine("Enter the maximum attempts you want to make for 'two of a kind':");

/*When i declared roll1 and roll2 with value=0, program wasn't entering the while loop since the codition

is satisfied because both roll1 and roll2 have value 0, so i tried this solution instead*/

Random numberGen= new Random();

int roll1=1;

int roll2=2;

int attempt=0;

Console.WriteLine("Press enter to roll");

while (roll1 !=roll2&&attempt!=max)

{

roll1=numberGen.Next(1,7);

roll2=numberGen.Next(1,7);

Console.WriteLine("Roll 1 : "+roll1+"\nRoll 2 : "+roll2);

attempt=attempt+1;

}

/*if the maximum attempt is reached this line prints out otherwise the else condition is satisfied*/

if (attempt==max)

{

Console.WriteLine("Sorry,You have run out of chances, Better luck next time.");

}

else

{

Console.WriteLine("Congrats! it took you "+attempt+" attempts to roll 'two of a kind'.");

}

}

}

}

• Member

I made an attempt, at first I made the mistake of putting int roll2 = 0;

using System;

namespace Tutorials

{

class Program

{

static void Main(string[] args)

// Dice Generator:

{

Console.ForegroundColor = ConsoleColor.Blue;

Console.Title = "DiceMania";

Random numberGen = new Random();

int roll1 = 0;

int roll2 = 1;

int attempts = 0;

Console.WriteLine("Press Enter to roll the 2 dice");

while (roll1 != roll2){

roll1 = numberGen.Next(1, 7);

roll2 = numberGen.Next(1, 7);

attempts++;

Console.WriteLine("Dice 1: " + roll1);

Console.WriteLine("Dice 2: " + roll2 + "\n ");

}

Console.WriteLine("It took you " + attempts + " attempts to roll two of a kind");

// wait before closing

}

}

}

• Member

Heres my solution for this one

```{
Random numberGen = new Random();

int roll = 0;
int roll2 = 1;
int attempt = 0;

Console.WriteLine("Press enter to roll the dice.");

while(roll != roll2) {

roll = numberGen.Next(1, 7);
roll2 = numberGen.Next(1, 7);

Console.WriteLine("Roll1: " + roll);
Console.WriteLine("Roll2: " + roll2);

attempt++;
}

Console.WriteLine("It took you " + attempt + " attempts to roll the same number on each die.");

// Wait
}
}
}
```
• Member

using System;

namespace ScriptLN4

{

class Program

{

static void Main(string[] args)

{

Console.ForegroundColor = ConsoleColor.Green;

Random numberGen = new Random();

int roll = 0;

int roll1 = 1;

int Attempts = 0;

Console.WriteLine("Press Enter to roll the dice");

while (roll != roll1)

{

roll = numberGen.Next(1, 7);

roll1 = numberGen.Next(1, 7);

Console.WriteLine("Roll01: " + roll);

Console.WriteLine("Roll02: " + roll1);

Attempts++;

}

Console.WriteLine("It took " + Attempts + " to roll the same number on both dice");

}

}

}

• Member

using System;

namespace lil_nigs_program

{

class Program

{

static void Main(string[] args)

{

Random numberGen = new Random();

int roll01 = 0;

int roll02 = 1;

int attempts = 0;

Console.WriteLine("Press enter to roll the Dice");

while(roll01 != roll02)

{

roll01 = numberGen.Next(1, 7);

roll02 = numberGen.Next(1, 7);

Console.WriteLine("Roll 1: " + roll01);

Console.WriteLine("Roll 2: " + roll02 +"\n");

attempts++;

}

Console.WriteLine("It took u " + attempts + "to roll two of a kind");

// Wait before closing

}

}

}

• Member

```using System;

namespace Test
{
class Program
{
static void Main(string[] args)
{
Random numberGen = new Random();

int roll_1 = 0;
int roll_2 = 1;
int attempts = 0;

Console.WriteLine("Press enter to roll the dice.");

while (roll_1 != roll_2)
{
Console.ForegroundColor = ConsoleColor.Cyan;
roll_1 = numberGen.Next(1, 7);
roll_2 = numberGen.Next(1, 7);
Console.WriteLine("\nRoll 1: " + roll_1);
Console.WriteLine("Roll 2: " + roll_2);
attempts++;
}
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("It took you " + attempts + " attempts to roll the same numbers.");

// wait before close
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("\nPress Enter to exit..");
}
}
}
```

• Member
edited April 2021

using System;

namespace První_hra

{

class Program

{

static void Main(string[] args)

{

Random numGen = new Random();

//variables

String lang;

String gameMode;

int roll01 = 0;

int roll02 = 1;

int attepts = 0;

//game

Console.WriteLine("cz/eng");

//eng

if(lang == "eng")

{

Console.WriteLine("Chose from these modes: hard/easy and write it below.");

//hard

if (gameMode == "hard")

{

while (roll01 != roll02)

{

roll01 = numGen.Next(1, 101);

roll02 = numGen.Next(1, 101);

Console.WriteLine("First number " + roll01);

Console.WriteLine("Second number " + roll02);

Console.WriteLine("________________");

attepts++;

}

Console.WriteLine("It took you " + attepts + " attepts");

}

// easy

if (gameMode == "easy")

{

while (roll01 != roll02)

{

roll01 = numGen.Next(1, 7);

roll02 = numGen.Next(1, 7);

Console.WriteLine("First number " + roll01);

Console.WriteLine("Second number " + roll02);

Console.WriteLine("________________");

attepts++;

}

Console.WriteLine("It took you " + attepts + " attepts");

}

}

//cz

if(lang == "cz")

{

Console.WriteLine("Vyber si z těhle módů: lehké/těžké, a napiš je pod tenhle text,");

//těžké

if (gameMode == "těžké")

{

while (roll01 != roll02)

{

roll01 = numGen.Next(1, 100);

roll02 = numGen.Next(1, 100);

Console.WriteLine("První číslo " + roll01);

Console.WriteLine("Druhé číslo " + roll02);

Console.WriteLine("________________");

attepts++;

}

Console.WriteLine("Dalo vám to " + attepts + " pokusů");

}

//lehké

if (gameMode == "lehké")

{

while (roll01 != roll02)

{

roll01 = numGen.Next(1, 7);

roll02 = numGen.Next(1, 7);

Console.WriteLine("První číslo " + roll01);

Console.WriteLine("Druhé číslo " + roll02);

Console.WriteLine("________________");

attepts++;

}

Console.WriteLine("Dalo vám to " + attepts + " pokusů");

}

}

//Ends the program

}

}

}

• Member

Assignment4:

```using System;

namespace C__Assignment4
{
class Program
{
static void Main(string[] args)
{
Random numberGen = new Random();

int roll1 = 0;
int roll2 = 1;
int attempts = 0;

Console.WriteLine("Press any key to roll both dies.");

while(roll1 != roll2) {

roll1 = numberGen.Next(1, 7);
roll2 = numberGen.Next(1, 7);

Console.WriteLine("Roll#1: " + roll1);
Console.WriteLine("Roll#2: " + roll2 + "\n");
attempts++;
}

Console.WriteLine("It took " + attempts + " attempts to get a two of a kind");

//Wait before closing
}
}
}
```
• Member

using System;

namespace C__project

{

class Program

{

static void Main(string[] args)

{

Random numberGen = new Random();

int roll1 = 0;

int roll2 = 1;

int attempts = 0;

Console.WriteLine("Press Enter to roll a die");

while(roll1 != roll2) {

roll1 = numberGen.Next(1, 7);

roll2 = numberGen.Next(1, 7);

Console.WriteLine("Roll1: " + roll1);

Console.WriteLine("Roll2: " + roll2);

attempts++;

}

Console.WriteLine("It took you " + attempts + " attempts to roll two equal numbers");

}

}

}

I feel like I've done something wrong with this thing, but it works, so hey, no need to fix :)

• Member

My solution:

I did the brackey's C# course episode 4 challenge, is my solution good?

using System;

namespace The_dice_roll

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine("Press any key to roll the Dice.");

int roll01 = 0;

int roll02 = 1;

int attempts = 0;

Random numberGen = new Random();

while(roll01 != roll02)

{

roll01 = numberGen.Next(1, 7);

roll02 = numberGen.Next(1, 7);

attempts++;

Console.WriteLine("\nYou got\nDice 1: " + roll01 + "\nDice 2: " + roll02);

}

Console.WriteLine("\nIt took you " + attempts + " rolls to get both dice to be the same number.");

}

}

}

• Member

using System;

namespace fartMachine

{

class Program

{

static void Main(string[] args)

{

Console.Title = "pffflarrpp";

Random numberGen1 = new Random(); //Random Number Generators

Random numberGen2 = new Random();

int roll1 = 1;

int roll2 = 0;

int attempts = 0;

Console.WriteLine("Press enter to roll the dice.");

while (roll1 != roll2)

{

roll2 = numberGen2.Next(1, 7); //Random number between 1-6

Console.WriteLine("You rolled " + roll2);

roll1 = numberGen1.Next(1, 7); //Random number between 1-6

Console.WriteLine("You rolled " + roll1 +"\n");

attempts++;

Console.WriteLine("Roll #" + attempts);

}

Console.WriteLine("You rolled a two of a kind after " + attempts +" attempts!");

//Wait Before Closing

}

}

}

• Member

Here's what I got:

using System;

namespace DusProgram

{

class Program

{

static void Main(string[] args)

{

Console.Title = ("DusProgram");

Console.ForegroundColor = ConsoleColor.White;

Console.WindowHeight = 30;

Random numberGen = new Random();

int roll1 = 0;

int roll2 = 1;

int attempts = 0;

Console.WriteLine("Press enter to roll the dice");

while(roll1 != roll2) {

roll1 = numberGen.Next(1, 7);

roll2 = numberGen.Next(1, 7);

Console.WriteLine("Rolled a " + roll1 + " and a " + roll2 + "!");

attempts++;

}

Console.WriteLine("Attempts: " + attempts);

// Wait before closing

}

}

}

I almost did it without looking for the solution, I just didn't know you need to set the second roll integer to "1".

• Member

using System;

namespace my_awesome_project

{

class Program

{

static void Main(string[] args)

{

// questiojn for 3 dice

// int roll01;

//int roll02;

//int roll03;

// main programmes starts throught here

Random numberGen = new Random();

int roll01 = 0;

int roll02 = 0;

int roll03 = 0;

int attempts = 0;

Console.WriteLine("Process enter to Role a Dice");

// I need help here (in while condition) , please somebody help me

while (roll01 != roll02; roll02 != roll03; roll03 != roll01 )

{

roll01 = numberGen.Next(1, 7);

roll02 = numberGen.Next(1, 7);

roll03 = numberGen.Next(1, 7);

Console.WriteLine("Roll 1: " + roll01);

Console.WriteLine("Roll 2: " + roll02 + "\n");

Console.WriteLine("Roll 3: " + roll03 + "\n");

attempts++;

}

Console.WriteLine("It took you " + attempts + " attempts to roll two of a kind.");

}

}

}

• Member

{

Random numberGen1 = new Random();

Random numberGen2 = new Random();

int roll2 = 1;

int roll1 = 0;

int attempts1 = 0;

Console.WriteLine("press enter to roll: ");

while (roll1 != roll2)

{

roll1 = numberGen1.Next(1, 7);

roll2 = numberGen2.Next(1, 7);

Console.WriteLine("you rolled: " + roll1 + " " + roll2);

attempts1++;

}

Console.WriteLine("it took you  " + attempts1 + " attempts to roll 2 of a kind ");

}

}

}

• Member

the best of them all (says me)

Random numgen1 = new Random();

var roll1 = 0;

var roll2 = 2;

var attempt = 0;

Console.WriteLine("press enter to roll the dice");

while (roll1 != roll2)

{

roll1=numgen1.Next(1,7);

roll2=numgen1.Next(1,7);

Console.WriteLine("you rolled"+roll1);

Console.WriteLine("you rolled"+roll2);

attempt++;

}

Console.WriteLine("it took you "+attempt+" attempts to roll two of a kind.");

• Member

Mine

using System;

namespace Again

{

class Program

{

static void Main(string[] args)

{

Random numberGen = new Random();

int roll1 = 0;

int roll2 = 0;

int attempts = 0;

Console.WriteLine("Press any key to roll.");

while (roll1 != 1 || roll2 != 1){

roll1 = numberGen.Next(1, 7);

roll2 = numberGen.Next(1, 7);

Console.WriteLine("You rolled: " + roll1 +" and " + roll2);

attempts++;

}

Console.WriteLine("It tooks you " + attempts + " attempts to roll the selected combination");

//To End