Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Need help

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help

    pseudocode for prgram i need to complete:

    set MIN to 0.5
    set MAX to 5.0
    set cumulativeValue to 0
    set count to 0
    set more to ‘y’
    while more is equal to ‘y’
    set count to count + 1
    print “Item number ” count “:”
    set value to MIN - 1.0
    while value is less than MIN or greater than Max
    print “Enter value (” MIN “ < value < ” MAX “): ”
    input value
    set cumulativeValue to cumulativeValue + value
    print “more? (y/n): ”
    input more
    set value to cumulativeValue / count
    print “Average value = ” value


    My current code:
    import java.util.Scanner;
     
    public class exercise5 {
     
     
    	public static void main(String[] args) {
    		Scanner stdIn = new Scanner (System.in);
    		double MIN = 0.5;
    		double MAX = 5.0;
    		double cumulativeValue = 0;
    		int count = 0;
    		int more = 'y';
    		String value;
     
    	while (more = 'y');
    	int count = count++ ;
    		System.out.print ("Item number" + count + ":");
    		double value = MIN -1.0;
    	while (value < MIN || value > MAX)
    		System.out.print ("Enter value(" + MIN + "<value<" + MAX + "):");
    		value = stdIn.nextLine();
    		double cumulativeValue = cumulativeValue + value;
    		System.out.print ("more? (y/n):");
    		more = stdIn.nextLine();
    		input cumulativeValue / count;
    	System.out.println("Average value =" value);

    I know its pretty bad code but bare with me. Any help on how to fix this would be greatly appreciated.
    Last edited by jps; November 6th, 2012 at 11:08 PM. Reason: added code tags

  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: Need help

    Hi billygoat
    Please see the announcements page for the use of code tags when posting code.

    How to fix what? What seems to be broken? What does it do instead of what you expected? Where does it seem to go wrong?

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help

    /**Code removed by moderator*/
    it will work properly
    Last edited by jps; November 8th, 2012 at 05:04 AM. Reason: spoonfeeding

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: Need help

    @kirannayana Please read The problem with spoonfeeding.

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help

    In "While loop" your not comparing value your assigning value to 'more' and your end while loop there only.It is suggestion for u must know about 'scope of variable' and 'while loop' and understand the problem properly it seems to so easy.

  6. #6
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help

    Quote Originally Posted by kirannayana View Post
    In "While loop" your not comparing value your assigning value to 'more' and your end while loop there only.It is suggestion for u must know about 'scope of variable' and 'while loop' and understand the problem properly it seems to so easy.
    Thank you so much for the help. It is now completely obvious where I messed up.

    p/s
    sorry it took me so long to reply back. homework has been killer lately