Практикум по программированию. Основы. Циклы. Автомат-продавец

From AsIsWiki
Revision as of 07:33, 14 April 2015 by Alex (Talk | contribs)

Jump to: navigation, search

Назад · Задачи · Дальше


Contents

Java

import java.util.Scanner;
import java.lang.Math;

public class Task11 {

    public static void main(String[] args) {
        
        Scanner in = new Scanner(System.in);
        
	System.out.println();
	System.out.println("----------- М А Г А З И Н -----------");

        System.out.print(" Введите количество единиц товара: ");
	long n = in.nextLong();

        System.out.print(" Введите стоимость одной единицы: ");
	double z = in.nextDouble();

        System.out.print(" Введите количество покупателей: ");
	long k = in.nextLong();

        System.out.println("-------------------------------------");

	double s, zp;
	long np;

	for (long i = 1; (i <= k) && (n != 0); i++) {

	    System.out.print(" Сумма покупателя N" + i + ": ");
	    s = in.nextDouble();

	    if (s < z) {

		System.out.println("   Денег не хватит даже на одну единицу товара");

	    } else {
		if (s > n * z) {

		    zp = s - z * n;
		    n = 0;

		    System.out.printf("   Скупаем весь товар, при этом остается %.2f руб\n", zp);

		} else {

		    np = (int) (s / z);
		    zp = s - np * z;
		    n -= np;

		    System.out.printf("   Покупаем %d единиц товара\n", np);
		    System.out.printf("   Сдача: %.2f руб.\n", zp);
		    System.out.printf("   У автомата остается %d единиц товара\n", n);

		}
	    }
	}
    }
}


C++



Pascal




Назад · Задачи · Дальше

Personal tools
Namespaces

Variants
Actions
Navigation
Tools