Jump to content


Assignment Question


  • Please log in to reply
3 replies to this topic

#1 lehart1

lehart1

    Newbie

  • Members
  • Pip
  • 4 posts
  • Gender:Male
  • Interests:boxing, it support, java programming

Posted 03 February 2012 - 12:43 PM

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++) {




   }


  }

}

#2 Kraicheck

Kraicheck

    Advanced Member

  • Members
  • PipPipPip
  • 884 posts
  • Gender:Male
  • Location:Belgium

Posted 03 February 2012 - 01:56 PM

So what exactly is the problem you're having?

#3 lehart1

lehart1

    Newbie

  • Members
  • Pip
  • 4 posts
  • Gender:Male
  • Interests:boxing, it support, java programming

Posted 05 February 2012 - 02:43 PM

View PostKraicheck, on 03 February 2012 - 01:56 PM, said:

So what exactly is the problem you're having?
basically i know i need to do an increment but not sure how to

#4 Kraicheck

Kraicheck

    Advanced Member

  • Members
  • PipPipPip
  • 884 posts
  • Gender:Male
  • Location:Belgium

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.
result += count
There's still a small problem with your loop but I'm sure you'll figure it out.