mladrad

RepoSys

Dec 1st, 2022
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1.     public static void main(String[] args) {
  2.         Scanner scan = new Scanner(System.in);
  3.  
  4.  
  5.         int target = Integer.parseInt(scan.nextLine());
  6.  
  7.         int cunt = 0;
  8.         double cash = 0;
  9.         double cred = 0;
  10.         double sumi = 0;
  11.  
  12.         String input = scan.nextLine();
  13.         while ((!"End".equals(input)) ) {
  14.  
  15.             int prod = Integer.parseInt(input);
  16.  
  17.             if (cunt % 2 == 0) {
  18.                 if (prod > 100 || prod <= 0) {
  19.                     System.out.println("Error in transaction!");
  20.                 } else {
  21.                     System.out.println("Product sold!");
  22.                     cash += prod;
  23.                     sumi += prod;
  24.                 }
  25.  
  26.             } else {
  27.                 if (prod <= 10) {
  28.                     System.out.println("Error in transaction!");
  29.                 } else {
  30.                     System.out.println("Product sold!");
  31.                     cred += prod;
  32.                     sumi += prod;
  33.                 }
  34.             }
  35.  
  36.             cunt++;
  37.             if (sumi >= target){
  38.                 break;
  39.             }
  40.  
  41.             input = scan.nextLine();
  42.         }
  43.  
  44.         if (sumi >= target ) {
  45.             System.out.printf("Average CS: %.2f%n", (cash / 2));
  46.             System.out.printf("Average CC: %.2f%n", (cred / 2));
  47.         }else{System.out.println("Failed to collect required money for charity.");
  48.  
  49.         }
  50.     }
  51. }
Add Comment
Please, Sign In to add comment