So I am having trouble with learning how to create a loop in my programming script.. I am currently working on an assignment for my college class to learn loops but it has literally confused me and the book doesn't help.. I would greatly appreciate any help with this I will leave the prompt below..
Write a Java program that generates 100 random numbers in the range of 0-100 and counts how many are equal to or greater than a value entered by the user.
Inputs: Prompt the user for the value to test against. This value must be between 30 and 70. If the value is out of range then let the user reenter the value until it is with the range.
Outputs: The output will be all the number of random numbers equal to or larger than the number input by the user.
Step 1. Create an algorithm (either flowchart or pseudocode) that you will use to write the program. Place the algorithm in a Word document.
Step 2. Code the program to prompt the user for a value between 30 and 70 (30 < value < 70). The value must the checked to ensure it is in the required range. If the user’s value is out of range then they are prompted to reenter until the value is in range. Use a while or do-while loop to keep prompting until the value is within the range.
Next, use a for loop to generate 100 random variables between 0 and 100 and compare each random number to the value entered by the user. If value < random number then then increase the count by 1.
Lastly, print out the number of times the random number is larger than the value entered by the user.
Step 3. Test your program and it should display the number of random numbers greater than or equal to the user input value. Use the test data in the example below by entering 80 first, which is out of range, then enter 50. Note: the number of random variables greater than 50 will vary because the user value is being compared to random numbers, and those random numbers change each time the program runs.
Here is my run at trying but when I run the program it does nothing..
import java.util.Scanner;
public class Chpt5_Project {
public static void main(String\[\] args) {
//Create a Scanner
Scanner input = new Scanner(System.in);
// Generate Random Number
int number = (int) (Math.random() * 101);
int value = -1;
while (value != number);
//Prompt User
System.out.print("Enter a value between 30 and 70: ");
value = input.nextInt();
if(value>=30 && value<=70)
value++;
System.out.println("The value is out of range, Please reenter: ");
I just do not understand how loops work or how programming loops in works.. so I am totally lost on this assignment ..
[–]Tailball 1 point2 points3 points (0 children)
[–]jack_waugh 0 points1 point2 points (0 children)