using System;
using System.Collections.Generic;
using System.Linq;
namespace MyApp // Note: actual namespace depends on the project name.
{
public class Program
{
public static void Main(string[] args)
{
// Title
Console.Title = "2 Dice rolls";
// Random Number
Random numGen = new Random();
// Variables
int roll1 = 0;
int roll2 = 0;
int attempts = 0;
Console.WriteLine("Press any key to roll the dice.");
// Main
Console.ReadKey();
roll1 = numGen.Next(1, 7);
roll2 = numGen.Next(1, 7);
Console.WriteLine("You rolled: " + roll1 + " and " +roll2);
attempts++;
while (roll1 != roll2) {
Console.ReadKey();
roll1 = numGen.Next(1, 7);
roll2 = numGen.Next(1, 7);
Console.WriteLine("You rolled: " + roll1 + " and " + roll2);
attempts++;
}
// Output number of attempts
Console.WriteLine("It took you " + attempts + " attemps to roll one of a kind.");
// Wait for input before closing
Console.ReadKey();
}
}
}
using System;
class Program
{
static void Main(string[] args)
{
Random numberGen = new Random();
int roll1 = 0; // dice 1
int attempts = 0; // attempts taken
int roll2 = 1; // dice 2
Console.WriteLine("Press enter to roll the dice.");
while(roll1 != roll2) { // loop
Console.ReadKey();
roll1 = numberGen.Next(1, 7); // rolling dice
Console.WriteLine("Dice 1 rolled: " + roll1);
roll2 = numberGen.Next(1, 7);
Console.WriteLine("Dice 2 rolled: " + roll2 + "\n");
attempts++;
}
Console.WriteLine("\nIt took you " + attempts + " attempts to get both dice equivalent."); //winning text
}
}
I decided that in order to memorize everything up until now in this course i had to give myself a mini-challange. So i made a simple gameish-calculator.
using System;
namespace MyApp // Note: actual namespace depends on the project name.
{
internal class Program
{
static void Main(string[] args)
{
Console.Title = "Dice";
Random numberGen = new Random();
double roll02 = 0;
double roll01 = 0;
int attempts = 0;
double i = numberGen.Next(1, 7);
Console.WriteLine("Press enter to roll the die.");
while (roll01 != i)
{
Console.ReadLine();
roll01 = numberGen.Next(1, 7);
roll02 = i;
Console.WriteLine("You rolled a " + roll01);
Console.WriteLine("You rolled a " + roll02);
attempts++;
}
Console.WriteLine("It took you " + attempts + " times to roll two of a kind.");
Console.ReadKey();
}
}
}
Comments
My Solution To Challeng4:
using System;
namespace yeet_le_program
{
class Challenge4
{
static void Main(string[] args)
{
Random numberGen = new Random();
int roll1 = 0;
int roll2 = 1;
int attempts = 0;
Console.WriteLine("Press Enter to roll the dice");
while(roll1 != roll2)
{
Console.ReadKey();
roll1 = numberGen.Next(1,7);
roll2 = numberGen.Next(1,7);
Console.WriteLine("You Rolled: "+roll1+","+roll2);
attempts++;
}
Console.WriteLine("It took you "+attempts+" attempts to roll 2 of the same kind");
Console.ReadKey();
}
}
}
I'm very proud of my solution :)
Quick question, how come it doesn't work unless int roll02 =1 ??
using System;
namespace Code_Relearn_Camp
{
class Program
{
static void Main(string[] args)
{
Random numberGen = new Random();
int roll1 = 0;
int roll2 = 1;
int attempts = 0;
Console.WriteLine("Press space to roll the die.");
while (roll1 != roll2)
{
Console.ReadKey();
roll1 = numberGen.Next(1, 7);
roll2 = numberGen.Next(1, 7);
Console.WriteLine("You rolled: " + roll1 + " and " + roll2);
attempts++;
}
Console.WriteLine("It took you " + attempts + " attempts to roll two of a kind");
//To make sure that this doesn't close immediately.
Console.ReadKey();
}
}
}
KurRuppted VS Code
using System;
using System.Collections.Generic;
using System.Linq;
namespace MyApp // Note: actual namespace depends on the project name.
{
public class Program
{
public static void Main(string[] args)
{
Random numberGen01 = new Random();
Random numberGen02 = new Random();
int roll01 = 2;
int roll02 = 1;
int attempts = 0;
Console.WriteLine("Press enter to roll the two dices!");
while(roll01 != roll02)
{
Console.ReadKey();
roll01 = numberGen01.Next(1,7);
roll02 = numberGen02.Next(1,7);
Console.WriteLine("Die 1: " + roll01);
Console.WriteLine("Die 2: " + roll02);
attempts ++;
}
Console.WriteLine("It took you " + attempts + " attempts to match both dies!");
Console.ReadKey();
}
}
}
// Heres a solution to check for only two 6's
// See https://aka.ms/new-console-template for more information
using System;
namespace MyApp // Note: actual namespace depends on the project name.
{
internal class Program
{
static void Main(string[] args)
{
Random numGen = new Random();
int roll01 = 0;
int roll02 = 0;
int attempts = 0;
Console.WriteLine("Press enter to roll");
while (roll01 != 6 && roll02 != 6)
{
Console.ReadKey();
roll01 = numGen.Next(1, 7);
roll02 = numGen.Next(1, 7);
Console.WriteLine("Dice 1 : " + roll01);
Console.WriteLine("Dice 2 : " + roll02);
attempts++;
}
Console.WriteLine("It took you "+ attempts + " to roll two 6's");
Console.ReadLine();
}
}
}
@svper Its because the condition while (roll01 != roll02)
using System;
namespace MyApp // Note: actual namespace depends on the project name.
{
internal class Program
{
static void Main(string[] args)
{
Random numGen = new Random();
int roll01 = 0;
int roll02 = 1;
int attempts = 0;
Console.WriteLine("Press enter to roll");
while (roll01 != roll02)
{
Console.ReadKey();
roll01 = numGen.Next(1, 7);
roll02 = numGen.Next(1, 7);
Console.WriteLine("Dice 1 : " + roll01);
Console.WriteLine("Dice 2 : " + roll02);
attempts++;
}
Console.WriteLine("It took you "+ attempts + " attempts to roll two " + roll01);
Console.ReadKey();
}
}
}
this was mine:
My attempt :|
// See https://aka.ms/new-console-template for more information
// Zmiana wygladu konsoli
Random numberGen = new Random();
int roll1 = 1;
int roll2 = 0;
int attempts = 0;
Console.WriteLine("Press ENTER to roll");
while(roll1 != roll2) {
Console.ReadKey();
roll1 = numberGen.Next(1, 7);
roll2 = numberGen.Next(1, 7);
Console.WriteLine("Dice 1: " + roll1);
Console.WriteLine("Dice 2: " + roll2);
Console.WriteLine();
attempts++;
}
Console.WriteLine("It took you " + attempts + " attempts to roll two dice of the same number");
// Wait before closing
Console.ReadKey();
I decided that in order to memorize everything up until now in this course i had to give myself a mini-challange. So i made a simple gameish-calculator.
// See https://aka.ms/new-console-template for more information
int result, number1, number2;
Console.WriteLine("How many calculations do you want to make? It cant be larger than 10");
Console.Write("Your number: ");
int calcNumber = Convert.ToInt16(Console.ReadLine());
while(calcNumber > 10) {
Console.Write("Your number cant be larger than 10\nYour number: ");
calcNumber = Convert.ToInt16(Console.ReadLine());
}
for (int i = 0; i < calcNumber; i++)
{
Console.WriteLine("\nPress 1 to add\nPress 2 to subtract\nPress 3 to multiply");
int decision = Convert.ToInt16(Console.ReadLine());
while(decision > 3) {
Console.WriteLine("\nPress 1 to add\nPress 2 to subtract\nPress 3 to multiply");
decision = Convert.ToInt16(Console.ReadLine());
}
Console.WriteLine("Here starts the calculation.");
Console.Write("First number: ");
number1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Second number: ");
number2 = Convert.ToInt32(Console.ReadLine());
switch(decision) {
case 1:
result = number1 + number2;
Console.WriteLine(number1 + " + " + number2 + " = " + result);
break;
case 2:
result = number1 - number2;
Console.WriteLine(number1 + " - " + number2 + " = " + result);
break;
case 3:
result = number1 * number2;
Console.WriteLine(number1 + " x " + number2 + " = " + result);
break;
}
}
// Wait before closing
Console.ReadKey();
here is the code:
Here is the outcome:
Have a great day!
Random numberGen = new Random();
int roll1 = 1;
int roll2 = 0;
int attempts = 0;
Console.WriteLine("Press enter to roll the dice.");
while(roll1 != roll2){
Console.ReadKey();
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 you "+ attempts + " attempts to roll the same number on both dice!");
Console.ReadKey();
using System;
namespace C_
{
class Program
{
static void Main(string[] args)
{
Random numGen = new Random();
int roll01 = 0;
int roll02 = 1;
int attemps = 0;
Console.WriteLine("Press enter to roll the dice.");
while(roll01 != roll02){
Console.ReadKey();
roll01 = numGen.Next(1, 7);
roll02 = numGen.Next(1, 7);
Console.WriteLine("First dice: " + roll01);
Console.WriteLine("Second dice: " + roll02 + "\n");
attemps++;
}
Console.Write("It tooks you " + attemps + " attemps to roll a the same number.");
Console.ReadKey();
}
}
}
using System;
namespace My_awesone_program
{
class Program
{
static void Main(string[] args)
{
Random numberGen1 = new Random();
Random numberGen2 = new Random();
int roll1 = 0;
int roll2 = 1;
int attempts1 = 0;
//int totalroll ;
Console.WriteLine("Press any key to roll the dice");
while (roll1 != roll2)
{
Console.ReadKey();
roll1 = numberGen1.Next(1, 7);
roll2 = numberGen2.Next(1, 7);
Console.WriteLine($"You rolled a {roll1} and a {roll2}");
attempts1++;
}
Console.WriteLine($"It took you {attempts1} attempts to roll the same dice");
//Wait before closing
Console.ReadKey();
}
}
}
Took me a while to realize that roll1 and roll2 first stared as 0, and it wouldnt loop. Until i saw the comments here and got how stupid I am haha!
okay I did it well im trying my best and this is what i got but it was obviously wrong
But thank you all i understood and learnt from my mistake<3
int roll1 = 0;
int roll2 = 1;
int attempts = 0;
Console.WriteLine("Press Enter to roll the die");
while(roll1 == roll2 && roll1 + roll2 !=6);
{
Console.ReadKey();
roll1 = numberGen.Next(1, 7);
roll2 = numberGen.Next(1, 7);
Console.WriteLine("You rolled: " + roll1 + roll2);
attempts++;
}
Console.WriteLine("IT TOOK YOU " + attempts + " attempts to roll the same dice.");
Console.ReadKey();
here's my solution!
Took a few tries but i managed it
this mine i make it a game for 2 player
using System;
namespace challege4
{
class MainClass
{
public static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.Gray
;
Random random = new Random();
int attempt = 0;
int roll1 = 0;
int roll2 = 1;
int player = 0;
Console.WriteLine("First to get same dice win.".ToUpper());
Console.WriteLine("Press enter to roll a dice.");
while (roll1 != roll2)
{
player++;
if (player % 2 == 0)
{
player = 2;
}
else
{
player = 1;
}
Console.ReadKey();
attempt++;
roll1 = random.Next(1, 7);
roll2 = random.Next(1, 7);
Console.WriteLine("Player " + player + ": You rolled " + roll1);
Console.WriteLine(" You rolled " + roll2);
}
Console.WriteLine("\n");
Console.WriteLine("Total attempt: " + attempt);
if (attempt % 2 == 0)
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Player 2 won!");
}
else
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Player 1 won!");
}
Console.ReadKey();
}
}
}
High Peaks CBD Gummies
High Peaks CBD Gummy Bears are miracle candies that provide you instant & long-lasting relief from issues with your mental, emotional, and physical https://www.sympla.com.br/produtor/cannaverdacbdgummiesnewyorek10001
https://www.facebook.com/people/Proper-CBD-Gummies-usa-2023/100091415070629/
https://www.facebook.com/people/Khonsu-CBD-Gummies-2023/100091447320675/
https://www.facebook.com/people/Choice-CBD-Gummies/100090188001280/
https://www.facebook.com/people/Pelican-CBD-Gummies-300mg/100090434027206/
https://www.facebook.com/people/Next-Plant-Cbd-Gummies-2023/100089769107382/
https://www.facebook.com/people/Smilz-CBD-Gummies-2023/100090157767400/
https://www.facebook.com/people/Ultra-CBD-Gummies/100091347065911/
https://www.facebook.com/people/Green-Leaf-CBD-Gummies/100091073324285/
https://www.facebook.com/people/Medallion-Greens-CBD-Gummies/100091406822948/
https://www.facebook.com/people/Biolife-CBD-Gummies/100091277649581/
https://www.facebook.com/people/TruFarm-CBD-Gummies/100090853257940/
https://www.facebook.com/people/True-North-CBD-Gummies/100089906479669/
https://www.sympla.com.br/produtor/eltorocbdgummies2023april
https://el-toro-cbd-gummies-6664f3.webflow.io/
https://www.sympla.com.br/produtor/cannaverdacbdimprovepainrelief2023
https://www.sympla.com.br/produtor/cannaverdacbdgummiesreviewsfactsunitedstates
https://www.sympla.com.br/produtor/khonsucbdgummiesrelievesanxietystressdontbuyuntilseethisdoesitworkornot
https://www.sympla.com.br/produtor/topbarbarawalterscbdgummiesforpaininflammationin2023
https://www.sympla.com.br/produtor/strictionbpreviewsunitedstates
https://www.sympla.com.br/produtor/highpeakscbdgummiesreviewsscamorlegitreaditfirstbeforebuyingseethis
https://www.sympla.com.br/produtor/ultraacbdgummiessandiego https://www.sympla.com.br/produtor/topbarbarawalterscbdgummiesforpaininflammationin2023
https://www.facebook.com/people/Trident-CBD-Gummies-usa/100090722870709/
https://www.facebook.com/Royalsupplements24hours.Official/
https://www.sympla.com.br/produtor/tridentcbdgummiesclaimyourtridentcbdgummies
https://www.sympla.com.br/produtor/tridentcbdgummiesreviewsonwebsitetridentcbdgummies
This is mine😀
using System;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
Random rollnum = new Random();
int rollone = 0;
int rolltwo = 1;
int attempts = 0;
Console.WriteLine("Press a key to roll the dice");
while (rollone != rolltwo)
{
Console.ReadKey();
rollone = rollnum.Next(1, 7);
rolltwo = rollnum.Next(1, 7);
Console.WriteLine("You Rolled: " + rollone + " and " + rolltwo);
attempts++;
}
Console.WriteLine("It took you " + attempts + " attempts to roll same numbers");
}
}
}
here is my solution to challenge 4
using System;
namespace Luck_checker
{
class Program
{
static void Main(string[] args)
{
//Appearance
Console.Title = "Luck Checker";
//roll die code
Random numberGen = new Random();
int roll = 0;
int roll2 = 1;
int attempts = 0;
Console.WriteLine("Press enter to roll the die.");
while(roll != roll2)
{
Console.ReadKey();
roll = numberGen.Next(1, 7);
roll2 = numberGen.Next(1, 7);
Console.WriteLine("Dice 1: " + roll);
Console.WriteLine("Dice 2: " + roll2 + "\n");
attempts++;
}
Console.WriteLine("It took you " + attempts + " attempts to roll two of one kind.");
// Wait before closing
Console.ReadKey();
}
}
}