1. Member
Join Date
Nov 2014
Posts
2
Rep Power
0

## Help with loops!

I'm doing a program where a user enters in exam results for students. Once he's entered the code, the code should split the results in stars in 4 categories.

I need help with a while loop that prints out infinite results. What I want to do is, if the user enters 2 digits, say "12", it should output 1 "*".

if the user enters "21" and "22", it should output "**".

there are 4 categories of marks which are marked with ints range1, range2, range3 and range4, which are user enter digits. Part 1 of the code is to split the user entered digits into its correct ranges. the ranges are 0-29, 30-39, 40-69 and 70-100. I've done the part where when the user enters a digit, it goes into the correct variable. After that when the user enters a digit over 100, the enter results should show up as stars. For example

Enter number =
21
22
44
66
44
23
11
111 (the 111 is where the program breaks and moves on)

so it should then display

0-29 ****
30-39
40-69 ***
70-100

whatever I'm trying, it displays an infinite amount of stars. If I try to use break, It only outputs a single star, no matter how many digits I enter

EDIT2: Here is the code

int mark = 0;
int range1 = 0, range2 = 0, range3 = 0, range4 = 0;
int count1 = 0, count2 = 0, count3 = 0, count4 = 0;

while (mark >=0 && mark <=100) {
System.out.println("Enter Exam Mark");

if (mark >0 && mark <=29) {
range1++;
}
if (mark >=30 && mark <=39) {
range2++;
}
if (mark >=40 && mark <=69) {
range3++;
}
if (mark >= 70 && mark <=100) {
range4++;

}

if (mark > 100) {
break;
}
}

while (range1>0) {
System.out.println("0-29");
count1 = range1++;
System.out.println("*");
}

"The problem is with the while loop, the one above is something I was experimenting with "
Last edited by Sukh_92; 11-30-2014 at 11:36 PM. Reason: ***

2. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
14

## Re: Help with loops!

Without seeing the code we can only guess at the problem.

Regards,
Jim

3. Member
Join Date
Nov 2014
Posts
2
Rep Power
0

## Re: Help with loops!

Originally Posted by jim829
Without seeing the code we can only guess at the problem.

Regards,
Jim
My apologies. I'll update the original post with the code I've compiled so far

4. ## Re: Help with loops!

When will the condition in the while() be false so the loop can exit?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•