Results 1 to 4 of 4
  1. #1
    Sukh_92 is offline Member
    Join Date
    Nov 2014
    Posts
    2
    Rep Power
    0

    Default 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 "**".

    EDIT: More info

    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");
    BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
    mark = Integer.parseInt(br.readLine());


    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; 12-01-2014 at 12:36 AM. Reason: ***

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Help with loops!

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

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Sukh_92 is offline Member
    Join Date
    Nov 2014
    Posts
    2
    Rep Power
    0

    Default Re: Help with loops!

    Quote Originally Posted by jim829 View Post
    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. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Help with loops!

    Please edit your post and wrap the code in code tags.

    When will the condition in the while() be false so the loop can exit?
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. New to Java please help!!! arrays loops while loops
    By Silver22 in forum New To Java
    Replies: 3
    Last Post: 05-29-2014, 02:11 AM
  2. Help with loops T_T
    By raffs03 in forum New To Java
    Replies: 16
    Last Post: 10-19-2012, 09:22 AM
  3. For Loops
    By Shyamz1 in forum New To Java
    Replies: 4
    Last Post: 09-27-2011, 10:41 PM
  4. Replies: 20
    Last Post: 03-22-2011, 05:02 AM
  5. Help with Loops
    By Spyderpig in forum New To Java
    Replies: 10
    Last Post: 02-17-2011, 09:10 AM

Posting Permissions

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