Results 1 to 7 of 7
- 04-23-2009, 04:20 AM #1
Member
- Join Date
- Apr 2009
- Posts
- 4
- Rep Power
- 0
How to loop a question when answer is negatve?
Hey guys I am trying to make this program that checks what your final grade is. I managed to make it work pretty well for someone new to java.
When you run the program your suppose to put the grade you got for the tests and stuff and it will then calculate your grade.
Now I am trying to make it so if a person puts a negative answer then it will ask the question again. I tried making a do while loop, but for some reason it keeps looping the first question non stop.
Can anyone help me make the program loop a question if the answer is negative or isn't a positive double? (a1, a2, t1, etc.)Last edited by brazuca; 04-23-2009 at 06:31 AM.
-
Where's your while loop?
- 04-23-2009, 04:39 AM #3
Member
- Join Date
- Apr 2009
- Posts
- 4
- Rep Power
- 0
I removed it, but it was after
a1 = Console.readDouble ("\nEnter the grade for your 1st assignment: ");
I just tried making it an "if else" statement, but I am not sure if that will cause the question to repeat.Last edited by brazuca; 04-23-2009 at 04:42 AM.
-
Have you studied creating separate methods yet? If you have, then using one can greatly simplify this problem here.
- 04-23-2009, 05:21 AM #5
Member
- Join Date
- Apr 2009
- Posts
- 4
- Rep Power
- 0
I just started studying coding so I don't know much more than what I have written. Other than that I made a program that makes shapes with stars.
How can I make it check after person puts an answer for (a1 <= 0) that it will repeat the question otherwise it would go to the next question which is a2?
-
I don't use a Console class, so I'm not sure how it works in particular, but I imagine something like:
Java Code:do { a1 = Console.readDouble ("\nEnter the grade for your 1st assignment: "); if (a1 < 0) { System.out.println("number entered must be positive only.") } } while (a1 < 0);
- 04-23-2009, 05:46 AM #7
Member
- Join Date
- Apr 2009
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Answer To Previous Question
By herbozo2003 in forum Java ServletReplies: 0Last Post: 03-02-2009, 02:22 AM -
Repeat while answer yes - do while loop
By AJ2009 in forum New To JavaReplies: 1Last Post: 01-10-2009, 06:19 PM -
Plz answer this question ...
By raghu2114 in forum Advanced JavaReplies: 2Last Post: 09-19-2008, 06:36 PM -
How to add or code for 'Question and Answer' on product page of website
By 82rathi.angara in forum Advanced JavaReplies: 1Last Post: 08-29-2008, 01:54 PM -
Question regarding foreach loop...
By theonlywalks in forum New To JavaReplies: 2Last Post: 03-15-2008, 06:15 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks