What's new

C & C++ POS

Shinki gami

Forum Veteran
Elite
Joined
Apr 27, 2017
Posts
1,405
Reaction
1,916
Points
824
Age
29
IMG_20220127_144729.jpg


Pano po lagyan ng kung ano pinili mo na order mga boss kunware yung 1 pipiliin ko sabay lalabas yung pizza na yun

C:
#include<stdio.h>

void main (void)
{
 int code, qty;
 float price, amt;
    
    
    printf("Welcome to League of Pizza how can we help you today\n\n");
           printf("================================MENU===============================");
    printf("[1]  Ezreal Ham and Cheese Pizza\t\tPhp 150.00\n");
    printf("[2]  Teemo Veggie Pizza\t\t\t\tPhp 180.00\n");
    printf("[3]  Jinx Ultimate Meat Pizza\t\t\tPhp 200.00\n");
    printf("[4]  Ekko BBQ Chicken Pizza\t\t\tPhp 230.00\n");
    printf("[5]  Sylas All-In Pizza\t\t\t\tPhp 300.00\n");
        printf("===================================================================");
    
           printf("\nEnter Code:  ");
           scanf("%d", &code);
           printf("\nEnter Quantity:  ");
           scanf("%d", &qty);
          
           switch(code)
           {
               case 1: price = 150.00;
                             break;
               case 2: price = 180.00;
                             break;
               case 3: price = 200.00;
                             break;
               case 4: price = 230.00;
                             break;
               case 5: price = 300.00;
                             break;
                             }
             amt = price * qty;
             printf("\nAmount: %.2f", amt);   
            
    
    
          
    
}
 

Attachments

Dapat i-implement mo hash para sa item:cost para mas matibay yung relation. Pwede ka gumami ng struct para dito. Tapos array ng structs (which is yung hash ng item:cost). Like sa baba yung sa line# 4.

Tapos sa line#57-68 yung array ng structs (o yung item:cost).

Sa pagkuha ng user input, mapapansin mo combination ng getline at sscanf yung ginamit ko kase mas safer yan kesa sa scanf (which is dangerous).

Yung switch code mo, walang strong relation yun sa item na prone sa mis-pairing.

C:
  1 #include <stdio.h>
  2 #include <stdlib.h>
  3
  4 typedef struct item {
  5   char* name;
  6   float price;
  7 } item;
  8
  9 void display_menu(item items[], size_t count) {
 10   const char* menu[] = {
 11                           "  +------------------------------------------------+",
 12                           "  |                      MENU                      |",
 13                           "  +================================================+",
 14                           "  |                                                |",
 15                           "  | 1. Ezreal Ham and Cheese Pizza\tPhp 150.00 |",
 16                           "  | 2. Teemo Veggie Pizza\t\tPhp 180.00 |",
 17                           "  | 3. Jinx Ultimate Meat Pizza\t\tPhp 200.00 |",
 18                           "  | 4. Ekko BBQ Chicken Pizza\t\tPhp 230.00 |",
 19                           "  | 5. Sylas All-In Pizza\t\tPhp 300.00 |",
 20                           "  |                                                |",
 21                           "  +------------------------------------------------+",
 22                         };
 23
 24   printf("\nWelcome to League of Pizza how can we help you today?\n\n");
 25   int n_menu = sizeof(menu)/sizeof(const char*);
 26   for (size_t i=0; i<n_menu; i++) {
 27     printf("%s", menu[i]);
 28     putchar('\n');
 29   }
 30
 31 }
 32
 33 void display_selection(item items[]) {
 34   char* mystream = malloc(sizeof(char) * 5);
 35   char* item = malloc(sizeof(char) * 5);
 36   size_t n_bytes = 10;
 37   int code;
 38   int quantity;
 39   printf("  Enter code: ");
 40   getline(&mystream, &n_bytes, stdin);
 41   sscanf(mystream, "%d", &code);
 42   code--;
 43
 44   printf("  Enter quantity: ");
 45   getline(&mystream, &n_bytes, stdin);
 46   sscanf(mystream, "%d", &quantity);
 47
 48   float amount = items[code].price * quantity;
 49   printf("\n  Your order: %s @ Php %.02f x %d = Php %.02f\n\n)", items[code].name, items[code].price, quantity, amount);                                                                                                                                    
 50 }
 51
 52 int main(int argc, char* argv[])
 53 {
 54   short count = 5;
 55   item all_items[count];
 56
 57   for (int i=0; i<count; i++) {
 58     all_items[0].name = "Ezreal Ham and Cheese Pizza";
 59     all_items[0].price = 150.00;
 60     all_items[1].name = "Teemo Veggie Pizza";
 61     all_items[1].price = 180.00;
 62     all_items[2].name = "Jinx Ultimate Meat Pizza";
 63     all_items[2].price = 200.00;
 64     all_items[3].name = "Ekko BBQ Chicken Pizza";
 65     all_items[3].price = 230.00;
 66     all_items[4].name = "Sylas All-In Pizza";
 67     all_items[4].price = 300.00;
 68   }
 69
 70   display_menu(all_items, count);
 71   display_selection(all_items);
 72   return 0;
 73 }
 
Last edited:
Dapat i-implement mo hash para sa item:cost para mas matibay yung relation. Pwede ka gumami ng struct para dito. Tapos array ng structs (which is yung hash ng item:cost). Like sa baba yung sa line# 4.

Tapos sa line#57-68 yung array ng structs (o yung item:cost).

Sa pagkuha ng user input, mapapansin mo combination ng getline at sscanf yung ginamit ko kase mas safer yan kesa sa scanf (which is dangerous).

Yung switch code mo, walang strong relation yun sa item na prone sa mis-pairing.

C:
  1 #include <stdio.h>
  2 #include <stdlib.h>
  3
  4 typedef struct item {
  5   char* name;
  6   float price;
  7 } item;
  8
  9 void display_menu(item items[], size_t count) {
 10   const char* menu[] = {
 11                           "  +------------------------------------------------+",
 12                           "  |                      MENU                      |",
 13                           "  +================================================+",
 14                           "  |                                                |",
 15                           "  | 1. Ezreal Ham and Cheese Pizza\tPhp 150.00 |",
 16                           "  | 2. Teemo Veggie Pizza\t\tPhp 180.00 |",
 17                           "  | 3. Jinx Ultimate Meat Pizza\t\tPhp 200.00 |",
 18                           "  | 4. Ekko BBQ Chicken Pizza\t\tPhp 230.00 |",
 19                           "  | 5. Sylas All-In Pizza\t\tPhp 300.00 |",
 20                           "  |                                                |",
 21                           "  +------------------------------------------------+",
 22                         };
 23
 24   printf("\nWelcome to League of Pizza how can we help you today?\n\n");
 25   int n_menu = sizeof(menu)/sizeof(const char*);
 26   for (size_t i=0; i<n_menu; i++) {
 27     printf("%s", menu[i]);
 28     putchar('\n');
 29   }
 30
 31 }
 32
 33 void display_selection(item items[]) {
 34   char* mystream = malloc(sizeof(char) * 5);
 35   char* item = malloc(sizeof(char) * 5);
 36   size_t n_bytes = 10;
 37   int code;
 38   int quantity;
 39   printf("  Enter code: ");
 40   getline(&mystream, &n_bytes, stdin);
 41   sscanf(mystream, "%d", &code);
 42   code--;
 43
 44   printf("  Enter quantity: ");
 45   getline(&mystream, &n_bytes, stdin);
 46   sscanf(mystream, "%d", &quantity);
 47
 48   float amount = items[code].price * quantity;
 49   printf("\n  Your order: %s @ Php %.02f x %d = Php %.02f\n\n)", items[code].name, items[code].price, quantity, amount);                                                                                                                                   
 50 }
 51
 52 int main(int argc, char* argv[])
 53 {
 54   short count = 5;
 55   item all_items[count];
 56
 57   for (int i=0; i<count; i++) {
 58     all_items[0].name = "Ezreal Ham and Cheese Pizza";
 59     all_items[0].price = 150.00;
 60     all_items[1].name = "Teemo Veggie Pizza";
 61     all_items[1].price = 180.00;
 62     all_items[2].name = "Jinx Ultimate Meat Pizza";
 63     all_items[2].price = 200.00;
 64     all_items[3].name = "Ekko BBQ Chicken Pizza";
 65     all_items[3].price = 230.00;
 66     all_items[4].name = "Sylas All-In Pizza";
 67     all_items[4].price = 300.00;
 68   }
 69
 70   display_menu(all_items, count);
 71   display_selection(all_items);
 72   return 0;
 73 }
ty boss kaso napasa ko na po gawa ko pero thank you pa din may natutunan ako sa code mo
 

Similar threads

Back
Top