/* Program: Project1 (Simple Vending Machine) Author: Hei-Wah Leung Class: CSCI 110 Date: 9-22-2003 Description: The vending machine wil only accept one dollar bill. The program would read an integer value between 0 and 3. Then the machine will calculates and return the change. I certify that: - All code used in my program is either my original work or was %ified by me from the source code published in the text of this course or provided by my instructor. - I have not used code obtained from another student, or any other unauthorized source, either %ified or un%ified. - I have not discussed or shared coding details of this program with anyone other than my instructor or MT. SAC tutors. I understand that I may discuss the concepts/ideas of this program with other students as long as we do not get down to the coding details. */ #include main () { int quarter, dime, nickel, penny, amount, x, y, c1, c2, c3, c4; while(amount !=-1){ printf("Enter a purchase amount [0 - 100] or type -1 to exit: "); scanf("%d",&amount); if(amount == -1){ printf("This program is written by Chi Tat Leung.\n"); printf("Thank you for using this program.\n"); } else if (amount <= 0){ printf("No more purchase. Good bye.\n"); printf("\n"); } else if (amount > 100){ printf("The amount you entered is invaild. Please try again.\n"); printf("\n"); } else{ printf("You entered a purchase amount of %d cents.\n",amount); y = amount; x = 100 - y; quarter = x / 25; amount = x % 25; c1 = quarter * 25; y = amount; dime = amount / 10; amount = amount % 10; c2 = dime * 10; y = amount; nickel = amount / 5; penny= amount % 5; c3 = nickel * 5; c4 = penny * 1; printf("Your change of %d cents is given as:\n",x); printf(" %d quarters (%d cents)\n",quarter,c1); printf(" %d dimes (%d cents)\n",dime,c2); printf(" %d nickels (%d cents)\n",nickel,c3); printf(" %d pennies (%d cents)\n",penny,c4); printf("The value of %d coins is %d cents.\n",quarter+dime+nickel+penny,x); printf("\n"); printf(". . .\n"); printf("\n"); } } return 0; }