In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use C language to achieve vending machines. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
The details are as follows
As shown in the simple vending machine shown in the picture, there are 10 kinds of goods on shelves 1 and 2, numbered as 1mi 10 in sequence, marked with price and name, and a number corresponding to an operable button for the selection of goods. If the goods on the shelf are bought by the user, the goods will be automatically taken out from the locker and sent to the shelf to ensure that there will be goods on the shelf. Users can invest more coins at one time, and can choose a variety of goods, vending machines can output goods and change at one time.
The operation method for users to buy goods:
(1) put coins from the "coin entrance" and put in a number of coins or banknotes in turn. The coin can support 1 yuan (banknote, coin), 2 yuan (banknote), 5 yuan (banknote) and 10 yuan (banknote). When putting the coin, the controller will first check and identify the value of the coin and count the total value of the coin, which will be displayed on the controller display screen to prompt the user to confirm that the coin has been placed.
(2) after confirming that the coin has been put in, the user can select the commodity, as long as he presses the numbered button on the outside of the corresponding commodity with his finger. For each item selected, the vending machine controller determines whether the coin is enough to buy. If the coin is enough, it automatically counts the item according to the number and calculates the required currency value, and prompts the balance. If the coin is insufficient, the controller prompts "Insufficient money". The user can cancel the purchase and all the coins will be returned to the user.
Input format:
First enter the sequence of coin values, ending with-1, and then enter multiple purchase numbers in turn, ending with-1.
Output format:
Export the total amount of coins and change, as well as the name and quantity of the goods purchased.
Enter a sample:
1 1 2 2 5 5 10 10-1
1 2 3 5 1 6 9 10-1
Sample output:
Total:36yuan,change:19yuan
Table-water:2;Table-water:1;Table-water:1;Milk:1;Beer:1;Oolong-Tea:1;Green-Tea:1
Solution 1:
# includeint main (void) {char a [10] [20] = {"Table-water", "Coca-Cola", "Milk", "Beer", "Orange-Juice", "Sprite", "Oolong-Tea", "Green-Tea"}; int b [11] = {0Green-Tea, change, sum = 0, change, flag=0 Scanf ("% d", & money); / / enter the currency value and calculate the total currency value while ((Moneyless colors 1) & & (money sum) {printf ("Insufficient money"); flag = 1; break;} icommodities; scanf ("% d", & c [I]);} change = sum-SUM; / / count the quantity of various goods with array b I = 1 While (c [I]! =-1) {switch (c [I]) {case 1: B [1] +; break; case 2: B [2] + +; break; case 3: B [3] + +; break; case 4: B [4] + +; break; case 5: B [5] + +; break; case 6: B [6] + +; break; case 7: B [7] +; break Case 8: B [8] + +; break; case 9: B [9] +; break; case 10: B [10] +; break; default:break;} iTunes;} / / output result if (flag==0) {printf ("Total:%dyuan,change:%dyuan\ n", sum, change); for (iTun1; isum) {printf ("Insufficient money") } else {change=sum-total; printf ("Total:%dyuan,change:%dyuan\ n", sum,change); for
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.