Advertisement
DoGy70

Untitled

Apr 24th, 2024
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. //1,2,5
  5.  
  6. //task2
  7.  
  8. typedef struct {
  9.     char name[50];
  10.     double price;
  11.     int productNum;
  12.  
  13. }Product;
  14.  
  15. typedef struct {
  16.     char address[100];
  17.     int productNum;
  18.  
  19. }Order;
  20.  
  21.  
  22.  
  23. int main()
  24. {
  25.     Product products[100];
  26.     Order orders[100];
  27.     int numProducts = 0;
  28.     int numOrders = 0;
  29.  
  30.     char command[10];
  31.  
  32.     while (scanf("%s",command)!= EOF){
  33.         if(strcmp(command, "Product") == 0){
  34.             scanf("%s %lf %d",products[numProducts].name,&products[numProducts].price,&products[numProducts].productNum);
  35.             for (int i = 0; i < numOrders; i++){
  36.                 if ( orders[i].productNum == products[numProducts].productNum){
  37.                     printf("Client %s ordered %s\n",orders[i].address,products[numProducts].name);
  38.                     for (int j =0; j<numOrders-1;j++){
  39.                         orders[j]= orders[j+1];
  40.                     }
  41.                     numOrders--;
  42.                     i--;
  43.                 }
  44.             }
  45.             numProducts--;
  46.         }
  47.         else if(strcmp(command, "Order")== 0){
  48.                 scanf("%s %d",orders[numOrders].address,&orders[numOrders].productNum);
  49.                 int found = 0;
  50.                 for (int i = 0;i <numProducts;i++){
  51.                     if(products[i].productNum == orders[numOrders].productNum){
  52.                         printf("Client %s ordered %s\n",orders[numOrders].address,products[i].name);
  53.                         found =1;
  54.                         break;
  55.                     }
  56.                 }
  57.                 if (!found){
  58.                     printf("Client %s waiting for the product\n",orders[numOrders].address);
  59.                     numOrders++;
  60.                 }
  61.                 else if(strcmp(command,"END")==0) {
  62.                         break;
  63.                         }
  64.  
  65.         }
  66.     }
  67.  
  68.  
  69.     return 0;
  70. }
  71. ///////////////////////////////////////////////////////
  72. #include <stdio.h>
  73. #include <stdlib.h>
  74. #include <math.h>
  75. #include <string.h>
  76. //taks1
  77.  
  78. double prices[] = {42.00, 13.99, 5.98, 21.02};
  79.  
  80. void calculateItems(int numGuests,int itemsBought[],int additionalItemsNeeded[]){
  81.     additionalItemsNeeded[0] = ceil((double)numGuests / 8) - itemsBought[0];
  82.     additionalItemsNeeded[1]= numGuests - itemsBought[1];
  83.     additionalItemsNeeded[2] = ceil((double)numGuests / 6) - itemsBought[2];
  84.     additionalItemsNeeded[3] = ceil((double)numGuests / 6) - itemsBought[3];
  85.  
  86. }
  87.  
  88.  
  89. int main()
  90. {
  91.     int numGuests;
  92.     printf("Enterthe number of guests:\n");
  93.     scanf("%d",&numGuests);
  94.  
  95.     int itemsBought[4]={0};
  96.     char item[10];
  97.     while(scanf("%s",item)){
  98.         if(strcmp(item,"PARTY!")==0)
  99.             break;
  100.         else if(strcmp(item,"Table")==0)
  101.             itemsBought[0]++;
  102.         else if(strcmp(item,"Chair")==0)
  103.             itemsBought[1]++;
  104.         else if(strcmp(item,"Cups")==0)
  105.             itemsBought[2]++;
  106.         else if(strcmp(item,"Dishes")==0)
  107.             itemsBought[3]++;
  108.     }
  109.  
  110.     int additionalItemsNeeded[4];
  111.     calculateItems(numGuests,itemsBought,additionalItemsNeeded);
  112.  
  113.     double totalCost=0;
  114.     for (int i =0; i <4; i++){
  115.         totalCost += prices[i] * itemsBought[i];
  116.     }
  117.  
  118.     printf("%.2lf\n",totalCost);
  119.  
  120.     if (additionalItemsNeeded[0]>0){
  121.         printf("%d Table\n",additionalItemsNeeded[0]);
  122.     }
  123.     if (additionalItemsNeeded[1]>0){
  124.         printf("%d Chair\n",additionalItemsNeeded[1]);
  125.     }
  126.     if (additionalItemsNeeded[2]>0){
  127.         printf("%d Cups\n",additionalItemsNeeded[2]);
  128.     }
  129.     if (additionalItemsNeeded[3]>0){
  130.         printf("%d Dishes\n",additionalItemsNeeded[3]);
  131.     }
  132.  
  133.  
  134.  
  135.  
  136.  
  137.     return 0;
  138. }
  139. ///////////////////////////////////////////////////////
  140. #include <stdio.h>
  141. #include <stdlib.h>
  142. #include <ctype.h>
  143. #include <string.h>
  144. //task5
  145.  
  146. int main()
  147. {
  148.     char word[100];
  149.     char guessed[100];
  150.     int length, i , tries =0;
  151.  
  152.     printf("Enter word: ");
  153.     scanf("%s",word);
  154.  
  155.     length = strlen(word);
  156.     printf("The length of the word is: %d\n",length);
  157.  
  158.     for (i = 0; i < length; i++){
  159.         guessed[i] = '_';
  160.     }
  161.     guessed[i=length] = '\0';
  162.     printf("Word: %s\n",guessed);
  163.  
  164.     while (tries < length+2){
  165.         char guess;
  166.         printf("Enter word: ");
  167.         scanf(" %c",&guess);
  168.  
  169.         int found = 0;
  170.         for (i=0; i < length;i++){
  171.             if(tolower(word[i])== tolower(guess)) {
  172.                 guessed[i]=word[i];
  173.                 found =1;
  174.             }
  175.         }
  176.             printf("Word: %s\n",guessed);
  177.  
  178.             if (strcmp(word, guessed) == 0){
  179.                 printf("Congrats! You guessed the word with %d letters",tries+1);
  180.                 break;
  181.             }
  182.             if (!found){
  183.                 tries++;
  184.                 printf("Wrong try! Thereis %d tries left!",length+2-tries);
  185.             }
  186.         }
  187.         if (tries >= length+2){
  188.             printf("You lost! The word was: %s\n",word);
  189.  
  190.         }
  191.         return 0;
  192.     }
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement