I posted with a program problem yesterday and couldn't get anywhere with all my errors. So I started over with a new program this morning and now have an infinate loop and a couple of questions about what is going on. My program is suppose to ask for total sales for the week, then find commission on those sales, add base salary of $200 then display a table with all salaries listed with "*" keeping tally of all inputs.
ex
200-299***
300-399*
and so on.
Here are my questions and my problem...When I run my program I input 1 sales figure and the program goes into a never ending loop. Why? ---and where are all the tallies "*" beside my references coming from and why?
(here is the output I receive)
100-199: ***
200-299: ****
300-399: *****
400-499: ******
500-599: *******
600-699: ********
700-799: *********
800-899: **********
00-99: **
Here is my code :
import java.util.Scanner;//program uses scanner
public class Sales
{
public static void main(String[] args)
{
Scanner input = new Scanner ( System.in);//scanner uses user input
int dollars;//used for sales
int WeeklySalary;//used for commission and weekly pay
int commission;//used for finding commission
int Sales[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10 };
System.out.println( "Enter total sales in dollar amount--" +
"enter a negative number to quit:");//prompt
//for salesman sales figures
dollars = input.nextInt();//accepts sales as dollars
while (dollars > 0)
{
commission = (int) (dollars * .09);//finds commission
WeeklySalary = commission + 200;//finds weekly pay
//for each array element, output a bar of the chart
for ( int counter = 0; counter < Sales.length; counter++ )
{
////output bar label ( "200-299:"....""900-999: ", 1000+: " )
if ( counter == 100 )
System.out.printf( "%5d: ", 1000);
else
System.out.printf( "%02d-%02d: ", counter * 100, counter *
100 + 99 );
//print bar of astrisks
for( int stars = 0; stars < Sales[ counter ]; stars++ )
System.out.print ( "*" );
System.out.println();//start a new line of output
}//end outer for
}//end while
}//end main
}//end class BarChart