Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- //1,2,5
- //task2
- typedef struct {
- char name[50];
- double price;
- int productNum;
- }Product;
- typedef struct {
- char address[100];
- int productNum;
- }Order;
- int main()
- {
- Product products[100];
- Order orders[100];
- int numProducts = 0;
- int numOrders = 0;
- char command[10];
- while (scanf("%s",command)!= EOF){
- if(strcmp(command, "Product") == 0){
- scanf("%s %lf %d",products[numProducts].name,&products[numProducts].price,&products[numProducts].productNum);
- for (int i = 0; i < numOrders; i++){
- if ( orders[i].productNum == products[numProducts].productNum){
- printf("Client %s ordered %s\n",orders[i].address,products[numProducts].name);
- for (int j =0; j<numOrders-1;j++){
- orders[j]= orders[j+1];
- }
- numOrders--;
- i--;
- }
- }
- numProducts--;
- }
- else if(strcmp(command, "Order")== 0){
- scanf("%s %d",orders[numOrders].address,&orders[numOrders].productNum);
- int found = 0;
- for (int i = 0;i <numProducts;i++){
- if(products[i].productNum == orders[numOrders].productNum){
- printf("Client %s ordered %s\n",orders[numOrders].address,products[i].name);
- found =1;
- break;
- }
- }
- if (!found){
- printf("Client %s waiting for the product\n",orders[numOrders].address);
- numOrders++;
- }
- else if(strcmp(command,"END")==0) {
- break;
- }
- }
- }
- return 0;
- }
- ///////////////////////////////////////////////////////
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <string.h>
- //taks1
- double prices[] = {42.00, 13.99, 5.98, 21.02};
- void calculateItems(int numGuests,int itemsBought[],int additionalItemsNeeded[]){
- additionalItemsNeeded[0] = ceil((double)numGuests / 8) - itemsBought[0];
- additionalItemsNeeded[1]= numGuests - itemsBought[1];
- additionalItemsNeeded[2] = ceil((double)numGuests / 6) - itemsBought[2];
- additionalItemsNeeded[3] = ceil((double)numGuests / 6) - itemsBought[3];
- }
- int main()
- {
- int numGuests;
- printf("Enterthe number of guests:\n");
- scanf("%d",&numGuests);
- int itemsBought[4]={0};
- char item[10];
- while(scanf("%s",item)){
- if(strcmp(item,"PARTY!")==0)
- break;
- else if(strcmp(item,"Table")==0)
- itemsBought[0]++;
- else if(strcmp(item,"Chair")==0)
- itemsBought[1]++;
- else if(strcmp(item,"Cups")==0)
- itemsBought[2]++;
- else if(strcmp(item,"Dishes")==0)
- itemsBought[3]++;
- }
- int additionalItemsNeeded[4];
- calculateItems(numGuests,itemsBought,additionalItemsNeeded);
- double totalCost=0;
- for (int i =0; i <4; i++){
- totalCost += prices[i] * itemsBought[i];
- }
- printf("%.2lf\n",totalCost);
- if (additionalItemsNeeded[0]>0){
- printf("%d Table\n",additionalItemsNeeded[0]);
- }
- if (additionalItemsNeeded[1]>0){
- printf("%d Chair\n",additionalItemsNeeded[1]);
- }
- if (additionalItemsNeeded[2]>0){
- printf("%d Cups\n",additionalItemsNeeded[2]);
- }
- if (additionalItemsNeeded[3]>0){
- printf("%d Dishes\n",additionalItemsNeeded[3]);
- }
- return 0;
- }
- ///////////////////////////////////////////////////////
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- //task5
- int main()
- {
- char word[100];
- char guessed[100];
- int length, i , tries =0;
- printf("Enter word: ");
- scanf("%s",word);
- length = strlen(word);
- printf("The length of the word is: %d\n",length);
- for (i = 0; i < length; i++){
- guessed[i] = '_';
- }
- guessed[i=length] = '\0';
- printf("Word: %s\n",guessed);
- while (tries < length+2){
- char guess;
- printf("Enter word: ");
- scanf(" %c",&guess);
- int found = 0;
- for (i=0; i < length;i++){
- if(tolower(word[i])== tolower(guess)) {
- guessed[i]=word[i];
- found =1;
- }
- }
- printf("Word: %s\n",guessed);
- if (strcmp(word, guessed) == 0){
- printf("Congrats! You guessed the word with %d letters",tries+1);
- break;
- }
- if (!found){
- tries++;
- printf("Wrong try! Thereis %d tries left!",length+2-tries);
- }
- }
- if (tries >= length+2){
- printf("You lost! The word was: %s\n",word);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement