so all i want to do is roll 1 die repeatedly and add it to a total until the total is equal to or greater than 31
this is what i have got to so far

``````import java.io.*;
import java.util.*;

public class comp {
public static void main(String[] args)
throws FileNotFoundException {

Scanner user = new Scanner(System.in);
Random r = new Random();

int roll;
int comptotal = 0;

do{
roll = r.nextInt(6) + 1;
comptotal = comptotal + roll;
}while (comptotal >= 31);
System.out.println(comptotal);
}}``````

it only rolls the die once i can't think of another way to roll the die again and keep rolling it until the total is equal to or greater than 31

2
Contributors
1
2
Views
8 Years
Discussion Span

You have your condition in the while backwards. You need to say that comptotal < 31 because it comes from 0 and adds until it equals or passes 31.

so all i want to do is roll 1 die repeatedly and add it to a total until the total is equal to or greater than 31
this is what i have got to so far

``````import java.io.*;
import java.util.*;

public class comp {
public static void main(String[] args)
throws FileNotFoundException {

Scanner user = new Scanner(System.in);
Random r = new Random();

int roll;
int comptotal = 0;

do{
roll = r.nextInt(6) + 1;
comptotal = comptotal + roll;
}while (comptotal >= 31);
System.out.println(comptotal);
}}``````

it only rolls the die once i can't think of another way to roll the die again and keep rolling it until the total is equal to or greater than 31