Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int expectedamount = Integer.parseInt(scanner.nextLine());
- int total = 0;
- double totalcard = 0;
- double totalcash = 0;
- int countcash = 0;
- int countcard = 0;
- int countpayments = 0;
- while(true){
- String nextLine = scanner.nextLine();
- if(nextLine.equals("End")){
- System.out.println("Failed to collect required money for charity.");
- break;
- }
- int price = Integer.parseInt(nextLine);
- countpayments++;
- if(countpayments % 2 == 1){
- if(price < 100){
- System.out.println("Product sold!");
- totalcash += price;
- total +=price;
- countcash++;
- }else {
- System.out.println("Error in transaction!");
- }
- }else{
- if(price > 10){
- System.out.println("Product sold!");
- totalcard += price;
- total +=price;
- countcard++;
- }else {
- System.out.println("Error in transaction!");
- }
- }
- if(total >= expectedamount){
- System.out.printf("Average CS: %.2f\n", totalcash / countcash);
- System.out.printf("Average CC: %.2f", totalcard / countcard);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment