Read from file array...

I think I might have had a brain aneurysm, trying to read this book trying to figure this out...

What I'm trying to do is make a file (rather than this stupid while loop) to input between 0-5 entries, 1-3 times, for 1-4 people covering 1-5 products and how much each product was worth, and then total it, and print it out in a pretty tabular format like this:

Product Sales Person 1 Sales Person 2 Sales Person 3 Sales Person 4 Total
1 0.00 0.00 0.00 0.00 0.00
2 0.00 0.00 0.00 0.00 0.00
3 0.00 0.00 0.00 0.00 0.00
4 0.00 0.00 0.00 0.00 0.00
5 0.00 0.00 0.00 0.00 0.00
Total 0.00 0.00 0.00 0.00

What I have doing it right now is a while loop (imagine how much of a pain that is):
[code] while ( salesPerson != 0 )
{
System.out.print( "Enter product number: " );
int product = input.nextInt();
System.out.print( "Enter sales amount: " );
double amount = input.nextDouble();

if ( salesPerson >= 1 && salesPerson < 5 &&
product >= 1 && product < 6 && amount >= 0 )
sales[ product - 1 ][ salesPerson - 1 ] += amount;
else
System.out.println( "Invalid input!" );

System.out.print( "

Enter another sales person number, press 0 to end: " );
salesPerson = input.nextInt();
}[/code]

So what I'm wanting to do is eliminate that whole while loop and put the read out into my for loops that build my table. Any ideas?

Comments

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion