help me with my code


Joined
Aug 6, 2021
Messages
1
Reaction score
0
Hey! so i recently took a YouTube playlist of learning how to program and I got this "homework" from the creator to make a code that based on what he said to do! and so i did that and i know the wrong line is on "while(roll1 = roll2)" and the result supposed to look like the photo on the attachment! hope you can help me!

here is the code:

using System;
namespace VS_code
{
internal class NewBaseType
{
static void Main(string[] args)
{
Random numberGen = new Random();
int roll1 = 0;
int roll2 = 0;
int attemps = 0;

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

while(roll1 = roll2) {
Console.ReadKey();

roll2 = numberGen.Next (1, 7);
roll1 = numberGen.Next (1, 7);
Console.WriteLine(" roll 1: " + roll1);
Console.WriteLine(" roll 2: " + roll2);
attemps++;
}

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



Console.ReadKey();

}
}
}
 

Attachments

  • Screenshot (12).png
    Screenshot (12).png
    175.1 KB · Views: 12
Ad

Advertisements

Joined
Mar 3, 2021
Messages
56
Reaction score
9
I haven't run the code, but try replacing the equals sign with a double-equals sign (==). As is, I'd suspect it is setting roll1 to roll2 (instead of comparing them) and always evaluating to true, causing that loop to never end (because the value is never zero). If that doesn't do the trick, I'll compile the code myself.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top