In the streets, automatic machines are also out everywhere giving you instant foods and drinks. One example of this machine is the soda machines, where you'll just insert a coin and automatically it will drop your choice of food or drink.
My idea is this, I thought that some of us love fruits, so some of us are always going to the market to buy some. Some hate delays because they're busy, so some of us depend on automatic vending machines. Now, the program that I will introduce to you today is the combination of the two ideas I have. It is called the Automated Fruit Selling Machine. This program is used for selling fruits easily. In the machine chosen fruits are all indicated and its prices. All you need to do is choose which fruit you would like to have, how many you would like to take and then the machine will automatically compute how much you need to pay and after that you can then get your orders.
The program is used with switch case statement for easier handling. Switch case statement is more user friendly when you need to make a wide variety of choices in your program. Check the codes below.
1: #include <stdio.h>
2: #include <conio.h>
3: #include <stdlib.h>
4:
5: int mango=0;
6: int apple=0;
7: int orange=0;
8: int durian=0;
9: int q1,q2,q3,q4;
10: main()
11: {
12: int order;
13: char a;
14:
15: printf("\t\tMENU\n[1]-Mango\t\t[3]-Orange\n[2]-Apple\t\t[4]-Durian\n");
16: printf("\nEnter your order: ");
17: scanf("%d", &order);
18:
19: switch(order){
20: case 1: system("cls");
21: printf("You entered Mango [P10/piece]");
22: printf("\n\nHow many: ");
23: scanf("%d", &q1);
24: mango=q1*10;
25: printf("\t\t= %d", mango);
26: break;
27: case 2: system("cls");
28: printf("You entered Apple [P15/piece]");
29: printf("\n\nHow many: ");
30: scanf("%d", &q2);
31: apple=q2*15;
32: printf("\t\t= %d", apple);
33: break;
34: case 3: system("cls");
35: printf("You entered Orange [P5/piece]");
36: printf("\n\nHow many: ");
37: scanf("%d", &q3);
38: orange=q3*5;
39: printf("\t\t= %d", orange);
40: break;
41: case 4: system("cls");
42: printf("You entered Durian [P60/piece]");
43: printf("\n\nHow many: ");
44: scanf("%d", &q4);
45: durian=q4*60;
46: printf("\t\t= %d", durian);
47: break;
48: default:printf("Invalid Input!");
49: }
50: printf("\n\n\nDo you have another order? (Y/N): ");
51: scanf("%s", &a);
52: switch(a){
53: case 'y': system("cls");
54: return main();
55: break;
56: case 'n': system("cls");
57: printf("Orders:\n");
58: if(q1!=0)
59: printf("Mango %d\t=%d", q1, mango);
60: if(q2!=0)
61: printf("\nApple %d\t=%d", q2, apple);
62: if(q3!=0)
63: printf("\nOrange %d\t=%d", q3, orange);
64: if(q4!=0){
65: printf("\nDurian %d\t=%d", q4, durian);}
66: printf("\n\nTotal: %d", mango+apple+orange+durian);
67: break;}
68:
69: getch();
70: }
In this program, there are four (4) different kinds of fruits namely Mango, Apple, Orange and Durian. Every one of the fruits has its prices Mango (P10), Apple (P15), Orange (P5) and Durian (P60). Now, the program runs like these. At first it will display all the available fruits inside the machine then it will ask you a question, "Enter your order: ". After you enter your choice it will be stored in the memory declared at the top namely int order. After choosing, your order will then undergo a comparison within the case statements in the program, if one of your choice which is your order matches a case statement then it will proceed to the next step which it will ask you another question, "How many: ". After entering how many fruits you'd like to take it will then continue to case 'n' which will compute how much you're going to pay. After that, it will ask you if you have another order, if not then you can simply input N for no. Check the sample outputs below.
I hope you learned something. Feel free to leave a comment below. Thanks!
thanks for sharing this website,please post some more information. C and C++ Training Institute in chennai | C and C++ Training Institute in anna nagar | C and C++ Training Institute in omr | C and C++ Training Institute in porur | C and C++ Training Institute in tambaram | C and C++ Training Institute in velachery
ReplyDelete