samedi 6 février 2016

is this a nested if? and while loop? not sure if I'm using them right. but I'm getting errors. "else without if"

//decides if user will get commission on top of pay.

import java.util.Scanner;

public class commiPay {

public static void main( String[] args )

{ Scanner input = new Scanner(System.in);

  int pay = 200;

  double com;//

  double sales;

  double x;

 while ( sales = -1 )// I want the user to enter positive numbers
  {
     System.out.printf( "Sales cannot be negative");

     System.out.printf( "Enter sales sold this week: ");
  }

  System.out.println("Enter sales made this week: ");
     sales = input.nextInt(); 

  if ( sales >= 7500 )/*got this format from the traditional letter grade java example**/
   {
     System.out.println( "Commission is multiplied by 5%. " );
     com = sales*.5;

 else if ( sales >= 5001 )

     System.out.println( "Commission is multiplied by 4%. " );
     com = sales*.4;
  else if ( sales >= 2501 )


     System.out.println( "Commission is multiplied by 3%. " );
    com = sales*.3;   
  else if ( sales >= 1001 )


     System.out.println( "Commission is multiplied by 2%. " );
     com = sales*.2;    
  else ( sales < 1000 )


     System.out.println( "No commission. " );
             total = pay;

   }

  System.out.println( "You will get paid" + total + "this week."  );

} } /*A salesperson is paid $200.00 a week plus a commission. The commission depends on the amount of sales he(she) has made during the week. Write a program that will prompt the user for the amount of sales for a week ( use an integer for the amount of sales ).

If the amount entered is less than 0, display an error message that tells the user "The sales amount cannot be negative!"

Using the information in the table below, determine what the salesperson's commission should be. The commission should be based on the total sales for the week.

Commission Table: up to 1,000 no commission 1,001 – 2,500 2% of sales 2,501 – 5,000 3% of sales 5,001 – 7,500 4% of sales over 7,500 5% of sales*/

Aucun commentaire:

Enregistrer un commentaire