Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.41 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. }
  102. int zeroarray(double input[])
  103. {
  104. int i = 0;
  105. while (i <21)
  106. {
  107.     input[i]=0;
  108.     i++;
  109. }
  110. return 0;
  111. }
  112. int printarray(double input[])
  113. {
  114.  int i = 0;
  115.  int j = 0;
  116.  double toPrint = 0;
  117.  while (i != 2)
  118.  {
  119.      toPrint=input[j];
  120.      if (toPrint == 0)
  121.      i = 2;
  122.      else{
  123.      printf("Item %i: %lf\n", (j+1),toPrint);
  124.      j++;
  125.      }
  126.  
  127.  }
  128.  return 0;
  129. }
  130. void additems(double input[], char name[])
  131. {
  132. double item = 1;
  133. int i = 0;
  134. int toggle = 0;
  135. while (item != 0)
  136.     {
  137.             printf("Enter %s's Item's (Price), (ENTER 0 FOR END)\n",name);
  138.             scanf("%lf",&item);
  139.             if(item == 0){
  140.             printarray(input);
  141.             printf("Is this correct? 1 - Yes, 2 - No\n");
  142.             scanf("%d",&toggle);
  143.             if (toggle == 1)
  144.             break;
  145.             else {
  146.                 goagain:
  147.             printf("Idiot! Which one is wrong? Enter number of item....\n");
  148.             scanf("%d",&toggle);
  149.             printf("Now enter price...\n");
  150.             scanf("%lf", &input[(toggle-1)]);
  151.             printf("You cool now? (1 - Yes, 2 -No");
  152.             scanf("%d",&toggle);
  153.             if (toggle == 1)
  154.             break;
  155.             else
  156.             goto goagain;
  157.             }
  158.             }
  159.             else{
  160.             input[i]=item;
  161.             i++;}
  162.     }
  163.     }
  164.  
  165. int sumarray(double input[])
  166. {
  167.     int i = 0;
  168.     int j = 0;
  169.     double total =0;
  170.     while (i != 2)
  171.     {
  172.         if (input[j]==0)
  173.         break;
  174.         total +=input[j];
  175.         j++;
  176.     }
  177.     return total;
  178.  
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement