jaOjaa

Untitled

Feb 27th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. #define index 4
  5.  
  6. void clrscr(){
  7. system("@cls||clear");
  8. }
  9.  
  10. int i;
  11.  
  12. typedef struct {
  13. int no;
  14. char code[6];
  15. int stock;
  16. int price;
  17. char name[30];
  18. }shop;
  19.  
  20. shop arrS[index] = {
  21. {01, "CR013", 5, 33000, "Bugatti Veyron"},
  22. {02, "CR107", 3, 41000, "Lexus LFA"},
  23. {03, "CR354", 1, 89000, "Audi R8"},
  24. {04, "CR731", 3, 62000, "BMW i8"}
  25. };
  26.  
  27. void header() {
  28. printf("| Welcome to\n");
  29. printf("| Prestige Motorcars Cashier\n");
  30. printf("| \n\n");
  31. }
  32.  
  33. void lists() {
  34. printf("| NO | CODE |\t\t NAME | STOCK | PRICE\t |\n");
  35. for (i=0; i<index; i++) {
  36. printf("| %d | %5s | %15s | %5d | Rp %d |\n", arrS[i].no, arrS[i].code, arrS[i].name, arrS[i].stock, arrS[i].price);
  37. }
  38. }
  39.  
  40. void menu() {
  41. printf("| Our product price lists\n\n");
  42. lists();
  43. printf("\n| Menus\n\n");
  44. printf(" 1. Sell\n 2. Add Stock\n 3. Exit");
  45. }
  46.  
  47. int main() {
  48. int choice, pil, sellqt, no, stock, price;
  49. char sellcode[6], code[6], name[30];
  50. header();
  51. home:
  52. menu();
  53. printf("\n\n| Select menu choice : ");
  54. scanf("%d", &choice);
  55. switch(choice) {
  56. case 1: {
  57. clrscr();
  58. do{
  59. printf("| You just chose 1!\n\n");
  60. lists();
  61. printf("\n\nPlease input the code [5 digit] : "); scanf("%s", &sellcode);
  62. for(i=0; i<index; i++) {
  63. if(strcmp(sellcode,arrS[i].code)==0) {
  64. printf("\n| Product found ! Name = %s",arrS[i].name);
  65. do{
  66. printf("\n| Please input quantity to sell [0..%d] : ", arrS[i].stock);scanf("%d", &sellqt);
  67. if(sellqt < arrS[i].stock) {
  68. arrS[i].stock = arrS[i].stock - sellqt;
  69. printf("\nTotal price is : Rp %d x %d = Rp %d", arrS[i].price, sellqt, arrS[i].price*sellqt);
  70. printf("\nThank you for selling.");
  71. getch();
  72. clrscr();
  73. goto home;
  74. }
  75. else {
  76. printf("| Quantity is not enough! \n");
  77. getch();
  78. choice = 5;
  79. }
  80. }while(choice == 5);
  81. }
  82. else if(index == 4 && strcmp(sellcode,arrS[i].code)!=0){
  83. choice = 4;
  84. }
  85. }
  86. }while(choice == 4);
  87. }
  88. case 2: {
  89. clrscr();
  90. do{
  91. printf("| You just chose 2!\n\n");
  92. lists();
  93. printf("\n\nPlease input the code [5 digit] : "); scanf("%s", &sellcode);
  94. for(i=0; i<index; i++){
  95. if(strcmp(sellcode,arrS[i].code)==0){
  96. printf("\nProduct found ! Name = %s", arrS[i].name);
  97. printf("\nInput quantity [0...%d] : ", arrS[i].stock);scanf("%d", &sellqt);
  98. arrS[i].stock = arrS[i].stock + sellqt;
  99. printf("\nStock successfully added.");
  100. getch();
  101. clrscr();
  102. goto home;
  103. }
  104. else if(index == 4 && strcmpi(sellcode,arrS[i].code)!=0){
  105. choice = 4;
  106. }
  107. }
  108. }while(choice == 4);
  109. }
  110. case 3: {
  111. clrscr();
  112. break;
  113. }
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment