/* Assignment 4 - Repetition using while */ /* CSC 157 */ /* Author: John Tracey */ /* email: jstracey456@yahoo.com */ /* This program asks for the number of customers */ /* to purchase zip disks. Each customer's data is entered */ /* specifically, the number of disks. If a customer buys */ /* more than 10 disks, a 10% discount apples to the entire */ /* order. If not, the customer pays $6.95 per disk. The */ /* program prints relevant cost information for each */ /* customer and provides summary data for the total order */ /* batch. */ #include int main() { /* define double precision variables for cost data */ /* zip_cost is $6.95 */ /* total_cost is the total for each individual customer */ /* grand_total_cost is the summary cost for all */ /* in the batch. */ double grand_total_cost, total_cost, zip_cost; /* define integer variables */ /* counter tracks the customer batch size for looping */ /* total_zip is total for each customer */ /* regular_zip tracks number of non-discounted disks */ /* discount_zip tracks discounted disks */ /* number_zip tracks total in batch */ /* munber_of_customers is an input for size of batch */ int counter, total_zip, regular_zip, discount_zip, number_zip, number_of_customers; /* initialize variables for proper calculation */ grand_total_cost = 0.0; counter = 1; /* initial value for while loop */ total_zip=0; regular_zip=0; discount_zip = 0; zip_cost = 6.95; printf ("How many customers will be handled at this time? "); scanf ("%d", &number_of_customers); /* This while loop repeats for the number of customers in the batch and compares the */ /*counter which is initialized at one to the number of customers, which can be any non-zero */ /*value. Inside the loop, if the customer purchases 10 or more disks, a 10% discount applies*/ /*to the enire order. If less than 10 disks are purchased,the regular price of $6.95 applies*/ while (counter <=number_of_customers) { printf ("\n\nPlease enter the number of zip disks ordered by customer%4d: ", counter); scanf ("%d", &number_zip); /* increment total for each customer */ total_zip=total_zip + number_zip; /* branch for discount pricing */ if (number_zip >= 10) { total_cost = 0.9*zip_cost*number_zip; /* caculate discount */ discount_zip=discount_zip + number_zip; /*accumulate totals for discounted disks*/ } /* branch for non-discounted disks */ else { total_cost = zip_cost*number_zip; regular_zip = regular_zip + number_zip; } /* print summary data for each customer */ printf ("\n\nCustomer:%4d\t#Zips:%4d\tCost:%6.2f", counter, number_zip, total_cost); grand_total_cost = grand_total_cost + total_cost;/* increment total cost for batch */ total_zip = regular_zip + discount_zip; /* increment total disks sold per batch*/ counter++; /* increment counter by 1 and repeat while loop */ /* Exit the loop when counter is greater than */ /* the number_of_customers. */ } /* Print summary data for all customers in the batch */ printf ("\n\nSummary Data:\n"); printf ("-----------------\n"); printf ("\tNumber of Zip Disks: %4d\n", total_zip); printf ("\tNumber of Zip Disks Discounted: %4d\n", discount_zip); printf ("\tRevenue from Zip Disks: %6.2f\n\n", grand_total_cost); return 0; }