hello everyone, i am currently working on my assignment and have hit a wall on one of the questions, i have done the majority of it but would be thankful for any tips on the rest of the program.
here is the question i am currently working on;
Create a graphical design and write a program that allows a whole number between 1 and 200 to be entered. If a number out of this range is entered then an error message should be shown and the user prompted for re-entry until a valid number is entered. When a valid number is entered then your program should total all numbers in the range from 1 and show the total. (ie: if 7 is entered then 1+2+3+4+5+6+7 = 28 ) The user should be asked if they want to enter another number and dependent on their answer the program will either politely exit or start again.
here is what i have so far;
/**
* @(#)Program 5.java
*
*
* @author
* @version 1.00 2012/2/2
*/
import java.util.Scanner;
class Template
{
public static void main (String[] args)
{
Scanner input = new Scanner(System.in);
int number, count =0;
do{
System.out.println("please enter a number between 1 and 200");
number = input.nextInt();
if ((number < 1) || (number > 200))
System.out.println("you are out of range, please try again!");
} while ((number < 1) || (number > 200));
for (count=1; count < number; count++) {
}
}
}
Assignment Question
Started by
lehart1
, Feb 03 2012 12:43 PM
3 replies to this topic
#1
Posted 03 February 2012 - 12:43 PM
#2
Posted 03 February 2012 - 01:56 PM
So what exactly is the problem you're having?
#4
Posted 10 February 2012 - 07:21 AM
It seems pretty straightforward to me.
Add a "result" variable outside the loop and increment it with count.
Add a "result" variable outside the loop and increment it with count.
result += countThere's still a small problem with your loop but I'm sure you'll figure it out.











