Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int printarray(double input[]);
- int zeroarray(double input[]);
- int sumarray(double input[]);
- void additems(double input[], char name[]);
- int main()
- {
- double shopTotal = 0;
- double basePrice = 0;
- double tomTotal = 0;
- double jamesTotal = 0;
- double alexTotal = 0;
- double danTotal = 0;
- double timTotal = 0;
- double tomOwnTotal = 0;
- double jamesOwnTotal = 0;
- double alexOwnTotal = 0;
- double danOwnTotal = 0;
- double timOwnTotal = 0;
- char NAME[50];
- double tomItems[20], jamesItems[20], alexItems[20], danItems[20], timItems[20];
- int toggle = 0;
- //zero arrays
- zeroarray(tomItems);
- zeroarray(jamesItems);
- zeroarray(alexItems);
- zeroarray(danItems);
- zeroarray(timItems);
- //adding items
- printf("Enter total amount for shopping:\n");
- scanf("%lf",&shopTotal);
- sprintf(NAME,"Tom");
- additems(tomItems, &NAME[0]);
- sprintf(NAME,"James");
- additems(jamesItems, &NAME[0]);
- sprintf(NAME,"Alex");
- additems(alexItems, &NAME[0]);
- sprintf(NAME,"Dan");
- additems(danItems, &NAME[0]);
- sprintf(NAME,"Tim");
- additems(timItems, &NAME[0]);
- //finding totals
- tomOwnTotal=sumarray(tomItems);
- jamesOwnTotal=sumarray(jamesItems);
- alexOwnTotal=sumarray(alexItems);
- danOwnTotal=sumarray(danItems);
- timOwnTotal=sumarray(timItems);
- //maffs
- basePrice=(shopTotal-(tomOwnTotal+jamesOwnTotal+danOwnTotal+alexOwnTotal+timOwnTotal))/5;
- tomTotal=basePrice+tomOwnTotal;
- jamesTotal=basePrice+jamesOwnTotal;
- alexTotal=basePrice+alexOwnTotal;
- timTotal=basePrice+timOwnTotal;
- danTotal=basePrice+danOwnTotal;
- //printing totals
- reprint:
- printf("Individual Totals are as follows:\n");
- printf("Tom's Total: %f\n",tomTotal);
- printf("James' Total: %f\n",jamesTotal);
- printf("Alex's Total: %f\n",alexTotal);
- printf("Dan's Total: %f\n",danTotal);
- printf("Tim's Total: %f\n",timTotal);
- //menus
- printf("To repeat, enter 1, to look at individual items, enter 2 or 3 to quit\n");
- scanf("%d",&toggle);
- if (toggle == 1)
- goto reprint;
- else if (toggle == 2){
- choice2:
- printf("Enter 1 for Tom, 2 for Alex, 3 for Tim, 4 for Dan, 5 for James\n");
- scanf("%d",&toggle);
- if (toggle == 1)
- printarray(tomItems);
- else if (toggle == 2)
- printarray(alexItems);
- else if (toggle == 3)
- printarray(timItems);
- else if (toggle == 4)
- printarray(danItems);
- else if (toggle == 5)
- printarray(jamesItems);
- }
- else if (toggle == 3)
- break;
- printf("Enter 1 for individual Totals 2 for individual items or 3 for quit\n");
- scanf("%d",&toggle);
- if (toggle == 1)
- goto reprint;
- else if (toggle == 2)
- goto choice2;
- else if (toggle == 3)
- return 0;
- end:
- return 0;
- }
- int zeroarray(double input[])
- {
- int i = 0;
- while (i <21)
- {
- input[i]=0;
- i++;
- }
- return 0;
- }
- int printarray(double input[])
- {
- int i = 0;
- int j = 0;
- double toPrint = 0;
- while (i != 2)
- {
- toPrint=input[j];
- if (toPrint == 0)
- i = 2;
- else{
- printf("Item %i: %lf\n", (j+1),toPrint);
- j++;
- }
- }
- return 0;
- }
- void additems(double input[], char name[])
- {
- double item = 1;
- int i = 0;
- int toggle = 0;
- while (item != 0)
- {
- printf("Enter %s's Item's (Price), (ENTER 0 FOR END)\n",name);
- scanf("%lf",&item);
- if(item == 0){
- printarray(input);
- printf("Is this correct? 1 - Yes, 2 - No\n");
- scanf("%d",&toggle);
- if (toggle == 1)
- break;
- else {
- goagain:
- printf("Idiot! Which one is wrong? Enter number of item....\n");
- scanf("%d",&toggle);
- printf("Now enter price...\n");
- scanf("%lf", &input[(toggle-1)]);
- printf("You cool now? (1 - Yes, 2 -No");
- scanf("%d",&toggle);
- if (toggle == 1)
- break;
- else
- goto goagain;
- }
- }
- else{
- input[i]=item;
- i++;}
- }
- }
- int sumarray(double input[])
- {
- int i = 0;
- int j = 0;
- double total =0;
- while (i != 2)
- {
- if (input[j]==0)
- break;
- total +=input[j];
- j++;
- }
- return total;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement