Click to See Complete Forum and Search --> : Help pls >< oak :(


ed81
11-11-2005, 01:00 PM
Hi:

I am sorry to bother again, thank you oak for the help the other day and I thought i was going to have a better idea about the program but i cant still run it the way the professor wants it and its due tomorrow. The proffessor wants it as simple as it can be i have this:(I know i must have thousands of errors but how would you correct this with what is here and simplest way as possible)

USER INPUTS ANY AMOUNT OF VALUES AND GETS THE SMALLER AT THE END

import java.util.Scanner;

public class Smaller {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
int c;
int min;
min = 0;
System.out.println("How many numbers you wish to enter?");
c = input.nextInt();
int n;

for (int counter = 1; counter<=c; counter++)
{
System.out.println("Please Enter the next number");
n = input.nextInt();

//HERE I NEED TO JUST USE THE IF STATEMENT TO GET IT RIGHT
//HAVE TRIED EVERYTHING.. EXCEPT THE RIGHT ONE
//HE SAYS THAT I JUST NEED TO STORE THE MINIMUM VALUE TO THE INT
//MIN AND THAT IT SHOULD DO
//I HAVE:

if (min<n) //i dunno how to compare it and get the value saved to min
{
System.out.println(min);
}
else
i dunno what to put here..

// need to compare with small here, update the smaller # to small (this was written by my professor)
}
}
}
I am so sorry to disturb you and take from your valuable time but i know you can give me the answer here np..

Best Regards and thank you very much
Ed

Waylander
11-13-2005, 08:12 PM
You know you "must" have a thousand errors? have you even tried to compile it?

Why dont you give it a go? try compile and run it, what happens? are there any specific errors that people could help you with?

Waylander.

Oak
11-14-2005, 07:07 AM
Ok.

Before you even go into the loop, you will store the first value that is entered in the min variable as it is the smallest value so far.

Once in the loop, you will check if the next number is smaller than min ( if ( n<min) ) and if it is true then store n in min otherwise do nothing.

At the end of the loop you will have the smallest number.

I would create the program for you but it is for your best benefit if you do it on your own and learn more. You will then be better at programming and get good grades at school.

Good Luck :)

ed81
11-15-2005, 10:46 AM
Thank you very much again Oak, I did it!! :) you were of great help.. I have more projects to work on such us "Employees Payroll" hehe, i am working on it so far it looks and works good I just have to add more to it. They want me to make the user input three names and calculate their salaries depending on the hours and rate they earn. I got it anyways. :)

Thannk you again
Regards
Edwin