— I am to write a program that prompts for N which is number of dice to roll and M for number of times to roll. I must repeat M times N6 or six sided die and compute and record the total sum of rolls. Using an array i must report how many times along with a percentage each possible total from 6 to 6N occurred.
Here is my code so far, i cannot get it to compile, and i think im going about it completely wrong, we only have one professor that teaches java, and he is not good at explaining things and always seems to be in a hurry if we ask questions. This is my second division class, and i learned barely anything the first semester.
////////////////////////////////
import java.util.Random;
import java.util.Scanner;
public class Lab1
{
public static Scanner in = new Scanner (System.in);
public static void main (String[] args)
{
int dice = 0;
int roll = 0;
while (true)
{
System.out.print ("How many dice do you roll?");
dice = in.nextInt();
}
System.out.print ("How many Times do you want to roll?");
roll = in.nextInt();
}
int dicetotal = Dicecount (dice); //Error message. dice cannot be resolved to Variable//
for (int i = 0; i< roll; i++)
System.out.println (Dicecount (dice));
}
}
public static int Dicecount ( int dice);
{
int dicetotal = 0;
for (int x = 0: x < dice; x++)
{
int rollcount = (int) (1+6* (Math.random()));
dicetotal+=rollcount;}
return dicetotal;
}
}
Properly format your code. This will help you find that the 6 lines starting with:
Are not within a function block, and need to be.
You also have a colon instead of a semi-colon in this line (~7th from the bottom):
Fixing these errors will allow your code to successfully compile – but that doesn’t mean that it will do what you want it to do. Since this is homework, you’ll be expected to find these issues and at least do initial troubleshooting on them yourself.