Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int printarray(double input[]);
  4. int zeroarray(double input[]);
  5. int sumarray(double input[]);
  6. void additems(double input[], char name[]);
  7. int main()
  8. {
  9.     double shopTotal = 0;
  10.     double basePrice = 0;
  11.     double tomTotal = 0;
  12.     double jamesTotal = 0;
  13.     double alexTotal = 0;
  14.     double danTotal = 0;
  15.     double timTotal = 0;
  16.     double tomOwnTotal = 0;
  17.     double jamesOwnTotal = 0;
  18.     double alexOwnTotal = 0;
  19.     double danOwnTotal = 0;
  20.     double timOwnTotal = 0;
  21.     char NAME[50];
  22.     double tomItems[20], jamesItems[20], alexItems[20], danItems[20], timItems[20];
  23.     int toggle = 0;
  24.    
  25.     //zero arrays
  26.     zeroarray(tomItems);
  27.     zeroarray(jamesItems);
  28.     zeroarray(alexItems);
  29.     zeroarray(danItems);
  30.     zeroarray(timItems);
  31.  
  32. //adding items
  33.     printf("Enter total amount for shopping:\n");
  34.     scanf("%lf",&shopTotal);
  35.     sprintf(NAME,"Tom");
  36.     additems(tomItems, &NAME[0]);
  37.     sprintf(NAME,"James");
  38.     additems(jamesItems, &NAME[0]);
  39.     sprintf(NAME,"Alex");
  40.     additems(alexItems, &NAME[0]);
  41.     sprintf(NAME,"Dan");
  42.     additems(danItems, &NAME[0]);
  43.     sprintf(NAME,"Tim");
  44.     additems(timItems, &NAME[0]);
  45.  
  46. //finding totals
  47.     tomOwnTotal=sumarray(tomItems);
  48.     jamesOwnTotal=sumarray(jamesItems);
  49.     alexOwnTotal=sumarray(alexItems);
  50.     danOwnTotal=sumarray(danItems);
  51.     timOwnTotal=sumarray(timItems);
  52.  
  53.     //maffs
  54.     basePrice=(shopTotal-(tomOwnTotal+jamesOwnTotal+danOwnTotal+alexOwnTotal+timOwnTotal))/5;
  55.     tomTotal=basePrice+tomOwnTotal;
  56.     jamesTotal=basePrice+jamesOwnTotal;
  57.     alexTotal=basePrice+alexOwnTotal;
  58.     timTotal=basePrice+timOwnTotal;
  59.     danTotal=basePrice+danOwnTotal;
  60.  
  61.  
  62. //printing totals
  63.     reprint:
  64.     printf("Individual Totals are as follows:\n");
  65.     printf("Tom's Total: %f\n",tomTotal);
  66.     printf("James' Total: %f\n",jamesTotal);
  67.     printf("Alex's Total: %f\n",alexTotal);
  68.     printf("Dan's Total: %f\n",danTotal);
  69.     printf("Tim's Total: %f\n",timTotal);
  70.  
  71. //menus
  72.     printf("To repeat, enter 1, to look at individual items, enter 2 or 3 to quit\n");
  73.     scanf("%d",&toggle);
  74.     if (toggle == 1)
  75.     goto reprint;
  76.     else if (toggle == 2){
  77.         choice2:
  78.     printf("Enter 1 for Tom, 2 for Alex, 3 for Tim, 4 for Dan, 5 for James\n");
  79.     scanf("%d",&toggle);
  80.     if (toggle == 1)
  81.         printarray(tomItems);
  82.     else if (toggle == 2)
  83.         printarray(alexItems);
  84.     else if (toggle == 3)
  85.         printarray(timItems);
  86.     else if (toggle == 4)
  87.         printarray(danItems);
  88.     else if (toggle == 5)
  89.         printarray(jamesItems);
  90.     }
  91.     else if (toggle == 3)
  92.     break;
  93.     printf("Enter 1 for individual Totals 2 for individual items or 3 for quit\n");
  94.     scanf("%d",&toggle);
  95.     if (toggle == 1)
  96.     goto reprint;
  97.     else if (toggle == 2)
  98.     goto choice2;
  99.     else if (toggle == 3)
  100.     return 0;
  101. end:
  102. return 0;
  103. }
  104. int zeroarray(double input[])
  105. {
  106. int i = 0;
  107. while (i <21)
  108. {
  109.     input[i]=0;
  110.     i++;
  111. }
  112. return 0;
  113. }
  114. int printarray(double input[])
  115. {
  116.  int i = 0;
  117.  int j = 0;
  118.  double toPrint = 0;
  119.  while (i != 2)
  120.  {
  121.      toPrint=input[j];
  122.      if (toPrint == 0)
  123.      i = 2;
  124.      else{
  125.      printf("Item %i: %lf\n", (j+1),toPrint);
  126.      j++;
  127.      }
  128.  
  129.  }
  130.  return 0;
  131. }
  132. void additems(double input[], char name[])
  133. {
  134. double item = 1;
  135. int i = 0;
  136. int toggle = 0;
  137. while (item != 0)
  138.     {
  139.             printf("Enter %s's Item's (Price), (ENTER 0 FOR END)\n",name);
  140.             scanf("%lf",&item);
  141.             if(item == 0){
  142.             printarray(input);
  143.             printf("Is this correct? 1 - Yes, 2 - No\n");
  144.             scanf("%d",&toggle);
  145.             if (toggle == 1)
  146.             break;
  147.             else {
  148.                 goagain:
  149.             printf("Idiot! Which one is wrong? Enter number of item....\n");
  150.             scanf("%d",&toggle);
  151.             printf("Now enter price...\n");
  152.             scanf("%lf", &input[(toggle-1)]);
  153.             printf("You cool now? (1 - Yes, 2 -No");
  154.             scanf("%d",&toggle);
  155.             if (toggle == 1)
  156.             break;
  157.             else
  158.             goto goagain;
  159.             }
  160.             }
  161.             else{
  162.             input[i]=item;
  163.             i++;}
  164.     }
  165.     }
  166.  
  167. int sumarray(double input[])
  168. {
  169.     int i = 0;
  170.     int j = 0;
  171.     double total =0;
  172.     while (i != 2)
  173.     {
  174.         if (input[j]==0)
  175.         break;
  176.         total +=input[j];
  177.         j++;
  178.     }
  179.     return total;
  180.  
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement