Good day everyone. My assignment is to create a point of sale system for a bakery shop. I have done all the coding up to the part when i have to do a 'order summary details' means i have to put all the user inputs into the order summary details. But i have no idea how do you do it. I have learnt array and managed to finish a part of it but when i try to use array for another part i cant do it and alot of errors. Im here seeking help as it is my last resort....I know im not suppose to ask for help but i really need help this time...
The expected output for order summary details are :

Order Summary Details:
Total bread type ordered: 3
Bread Type #1:
Type : Bun
Number of Unit : 4
Filling Flavour : Coconut(2)
Sub-Total : RM14.50
Bread Type #2:
Type : White Loaf
Number of Unit: 3
Sub-Total : RM15.00
Bread Type #3:
Type : Croissant
Number of Unit: 5
Filling Flavour: Chocolate(2) + Chicken(3).
Sub-Total : RM22.65
Total sale is RM52.15
The customer is entitled for a ice cream.

The link to the code :

https://pastebin.com/3kc7VW1f

My thought here is you have coded before your design was complete. Your code doesn't reveal your design without reverse engineering.

Did you create your data and design document and can you post that?

commented: I just code while looking at the output given by my lecturer. I did not create a data and design tho +0

Without a design, this code might be reverse engineered which is asking a lot. When I need help I have to supply a mimimum viable example of the issue and in situations where there is over a screen full of code, a design. Here I would have to pick through your design to find where the data lives to create your report.
But that's your work.

So let me recap: Think of the receipt as a data report. Your data lives somewhere. You are writing a small routine to access then print/report the needed output.

So this is whats happening. When i try to make a code at the end(order summary details). This is what i get. I know im doing something wrong because im data receiver is only receiving the recent input by user. So my question is how do i make it so that my order summary details takes the input from the do while loop that i have created in the beginning. I have tried using arrays but problem arises when there are conditions. Im still new to c programming so im not familiar with making a design...

help2.png

help.png

This post has no text-based content.

I'd be guessing here that the current output spacing is a little off. Please state what is wrong with the current output.

help3.png

This is the full problem that im currently facing.

The num of unit, filling flavour, subtotal, and grandtotal follows the most recent input. The input by user in the first part of the program is not the same as the ending which is the order summary details. Recently i had a problem with the breadtype but i fixed it with arrays. But when i try to do the same with the rest, theres complication.

Please post your code in this thread. When your link eventually goes dead this thread will not be helpful to anyone else.

If I might be blunt: what idiot taught you to use goto like that?

The goto statement and labels do have some legitimate uses. These are not those. It is an extremely bad idea to use goto indiscriminately like this.

If your instructor has taught an introductory class to use goto at all, you ought to report them to the school administration for incompetence and walk out of the course. Period, end of subject.

Having vented my spleen on this topic now, I would also mention:

  • The lack of decomposition into separate functions.
  • the naming of variables in the form name1, name2, ... nameN, rather than using an array.
commented: Good choice of the word decomposition. Over time this code will decompose and smell bad. +16

To speed things along, I'll save the OP the trouble of posting the code here:

#include <stdio.h>
int main()
{
  // Displaying menu for customers
  printf("\n%115s", "GEBU BAKERY SHOP");
  printf("\n%121s", "Bread Types and Pricing Detail\n");
  printf("\n%162s","____________________________________________________________________________________________________________\n");
  printf("%53s%30s%22s%22s%35s", "|", "|", "|", "|", "|");
  printf("\n%53s%15s%15s%15s%7s%15s%7s%26s%9s", "|", "Bread type", "|", "Unit price", "|", "Unit price", "|", " Filling price/unit", "|");
  printf("\n%53s%30s%17s%5s%16s%6s%35s", "|", "|", "(self collect)","|", "(Food Panda)", "|", "|");
  printf("\n%163s","|_____________________________|_____________________|_____________________|__________________________________|\n");
  printf("%53s%30s%22s%22s%35s", "|", "|", "|", "|", "|");
  printf("\n%53s%16s%14s%14s%8s%14s%8s%27s%8s", "|", "1) White Loaf", "|", " RM 5.00", "|", "RM 5.50", "|", "- RM 1.20 (Chocolate)", "|");
  printf("\n%127s%36s","|_____________________________|_____________________|_____________________|", "|\n");
  printf("%53s%30s%22s%22s%25s%10s", "|", "|", "|", "|", "- RM 1.50 (Coconut)", "|");
  printf("\n%53s%16s%14s%14s%8s%14s%8s%35s", "|", "2) Wheat Loaf", "|", " RM 5.50", "|","RM 6.00", "|", "|");
  printf("\n%127s%24s%12s","|_____________________________|_____________________|_____________________|", "- RM 1.00 (Pandan)", "|\n");
  printf("%53s%30s%22s%22s%35s", "|", "|", "|", "|", "|");
  printf("\n%53s%19s%11s%14s%8s%14s%8s%25s%10s", "|", "3) Bun + Filling", "|", "RM 2.00", "|", "RM 2.50", "|", "- RM 1.75 (Chicken)", "|");
  printf("\n%53s%30s%17s%5s%22s%35s", "|", "|", "(no filling)","|", "|", "|");
  printf("\n%127s%24s%12s","|_____________________________|_____________________|_____________________|", "- RM 1.00 (Butter)", "|\n");
  printf("%53s%30s%22s%22s%35s", "|", "|", "|", "|",  "|");
  printf("\n%53s%25s%5s%14s%8s%14s%8s%35s", "|", "4) Croissant + filling", "|", "RM 3.00", "|", "RM 3.50", "|", "|");
  printf("\n%53s%30s%17s%5s%22s%35s", "|", "|", "(no filling)","|", "|", "|");
  printf("\n%163s","|_____________________________|_____________________|_____________________|__________________________________|\n");

  printf("\n%156s", "Special Promotion!! : Free Ice cream when you purchase more than RM 50.00 (forself-collect only)\n");
  printf("\n%144s", "*Food Panda has a default delivery surcharge of RM5.00 for every order.*\n");

  //User-interface  
  int collect = 0;
  int bread;
  int breadnum;
  int breadtype[4]; //An array is used to store data and used in Order summary details
  int breadunit;
  char filling = 0;
  int fillingflavour = 0;
  int numberflavour1;
  int numberflavour2;
  int numberflavour3;
  int numberflavour4;
  int numberflavour5;
  int numberflavour6;
  float breadtotal;
  float fillingtotal1;
  float fillingtotal2;
  float fillingtotal3;
  float fillingtotal4;
  float fillingtotal5;
  float fillingtotal6;
  float subtotal;
  int sum;

  //Choosing between Self-Collect or FoodPanda  
 startagain : printf("\n%100s", "Enter type of order (1-Self-Collect, 2-Food Panda): ");
  scanf("%d", &collect);

  switch(collect)
    {
    case 1 :
      goto Breadtype;
      break;

    case 2 :
      goto Breadtype;
      break;

    default :
      printf("                                                Please enter either '1' or '2'");
      goto startagain; //If user enter other numbers besides 1 or 2, programme will be directed back to start again hence the goto statement

    }  

  //Breadtype   
 Breadtype : printf("\n%84s" , "Enter how many bread type to order: ");
  scanf("%d", &bread);

  breadnum=1;
  do
    {
      printf("\n                                                Bread type #%d : \n ",breadnum);
    breadstartagain : printf("\n%119s", "Enter the bread type (1-White Loaf, 2-Wheat Loaf, 3-Bun, 4-Croissant): ", breadtype);
      scanf("%d,", &breadtype[breadnum]);

      if(collect == 1)  //Self-Collect prices
    switch(breadtype[breadnum])
          {
          case 1 :
            breadtotal = 5.00;
            break;

          case 2 :
            breadtotal = 5.50;
            break;

          case 3 :
            breadtotal = 2.00;
            break;

          case 4 :
            breadtotal = 3.00;
            break;

          default :
            printf("%97s", "Please choose according to the numbers assigned!\n");
            goto breadstartagain;       
          }
      else if(collect ==2) //FoodPanda prices
    switch(breadtype[breadnum])
          {
          case 1 :
            breadtotal = 5.50;
            break;

          case 2 :
            breadtotal = 6.00;
            break;

          case 3 :
            breadtotal = 2.50;
            break;

          case 4 :
            breadtotal = 3.50;
            break;

          default :
            printf("%97s", "Please choose according to the numbers assigned!\n");
            goto breadstartagain; //If user enters numbers that  are not related to choice given, it will restart the process at choosing bread again
          }
      //Choosing number of unit for bread chosen
    numofunit : printf("%70s", "Enter number of unit: ");
      scanf("%d", &breadunit);

      //Choosing flavour
      //Theres 6 copies of choosing flavour just incase user wants to input more than one type of flavour. Since there are 5 and user might input more than intended input, 6 is used just to be safe.
    choosefillingagain : printf("%92s", "Do you want to add filling? [Y-Yes, N-No] : ");
      scanf("%c", &filling);
      filling = getchar(); //To ensure a character is entered

      if (filling =='y')
        goto chooseflavour;
      else if (filling =='Y')
        goto chooseflavour;
      else if (filling == 'n')
        goto subtotal;
      else if (filling =='N')
        goto subtotal;
      else if (filling != 'y'||'Y'||'n'||'N')
        printf("%78s", "Please type either 'Y' or 'N'\n");
      goto choosefillingagain;

    chooseflavour : printf("%128s", "Choose filling flavour(1-Chocolate, 2-Coconut, 3-Pandan, 4-Chicken, 5-Butter) : ");
      scanf("%d", &fillingflavour);

      switch(fillingflavour)
        {
        case 1 :
          printf("%92s","Enter number of unit for chocolate filling: ");
          scanf("%d", &numberflavour1);
          fillingtotal1 = (numberflavour1 * 1.20);
          break;

        case 2 :
          printf("%90s","Enter number of unit for coconut filling: ");
          scanf("%d", &numberflavour1);
          fillingtotal1 = (numberflavour1 * 1.50);
          break;

        case 3 :
          printf("%89s","Enter number of unit for pandan filling: ");
          scanf("%d", &numberflavour1);
          fillingtotal1 = (numberflavour1 * 1.00);
          break;

        case 4 :
          printf("%90s","Enter number of unit for chicken filling: ");
          scanf("%d", &numberflavour1);
          fillingtotal1 = (numberflavour1 * 1.75);
          break;

        case 5 :
          printf("%89s","Enter number of unit for butter filling: ");
          scanf("%d", &numberflavour1);
          fillingtotal1 = (numberflavour1 * 1.00);
          break;

        default :
          printf("%109s", "Your chosen flavour is not in the list. Please choose again.\n");
          goto chooseflavour; 
        }
      if (numberflavour1 > breadunit)
        printf("\n%144s", "Number of flavour chosen exceeded number of breads. Please enter correct amount of flavour unit\n");
      else if (numberflavour1 == breadunit)
        goto subtotal;
      else if (numberflavour1 < breadunit)
        goto choosefillingagain1;

      //Choose flavour again 1                      
    choosefillingagain1 : printf("%92s", "Do you want to add filling? [Y-Yes, N-No] : ");
      scanf("%c", &filling);
      filling = getchar();
      if (filling =='y')
        goto chooseflavour2;
      else if (filling =='Y')
        goto chooseflavour2;
      else if (filling == 'n')
        goto subtotal;
      else if (filling =='N')
        goto subtotal;
      else if (filling != 'y'||'Y'||'n'||'N')
        printf("%78s", "Please type either 'Y' or 'N'\n");
      goto choosefillingagain1;

    chooseflavour2 : printf("%128s", "Choose filling flavour(1-Chocolate, 2-Coconut, 3-Pandan, 4-Chicken, 5-Butter) : ");
      scanf("%d", &fillingflavour);

      switch(fillingflavour)
        {
        case 1 :
          printf("%92s","Enter number of unit for chocolate filling: ");
          scanf("%d", &numberflavour2);
          fillingtotal2 = (numberflavour1 * 1.20);
          break;

        case 2 :
          printf("%90s","Enter number of unit for coconut filling: ");
          scanf("%d", &numberflavour2);
          fillingtotal2 = (numberflavour1 * 1.50);
          break;

        case 3 :
          printf("%89s","Enter number of unit for pandan filling: ");
          scanf("%d", &numberflavour2);
          fillingtotal2 = (numberflavour1 * 1.00);
          break;

        case 4 :
          printf("%90s","Enter number of unit for chicken filling: ");
          scanf("%d", &numberflavour2);
          fillingtotal2 = (numberflavour1 * 1.75);
          break;

        case 5 :
          printf("%89s","Enter number of unit for butter filling: ");
          scanf("%d", &numberflavour2);
          fillingtotal2 = (numberflavour1 * 1.00);
          break;

        default :
          printf("%109s", "Your chosen flavour is not in the list. Please choose again.\n");
          goto chooseflavour2;


        }
      sum = (numberflavour1 + numberflavour2);
      if (sum > breadunit)
        printf("\n%144s", "Number of flavour chosen exceeded number of breads. Please enter correct amount of flavour unit\n");
      else if (sum == breadunit)
        goto subtotal;
      else if (sum < breadunit)
        goto choosefillingagain2;

      //Choose flavour again 2                      
    choosefillingagain2 : printf("%92s", "Do you want to add filling? [Y-Yes, N-No] : ");
      scanf("%c", &filling);
      filling = getchar();
      if (filling =='y')
        goto chooseflavour2;
      else if (filling =='Y')
        goto chooseflavour2;
      else if (filling == 'n')
        goto subtotal;
      else if (filling =='N')
        goto subtotal;
      else if (filling != 'y'||'Y'||'n'||'N')
        printf("%78s", "Please type either 'Y' or 'N'\n");
      goto choosefillingagain2;

    chooseflavour3 : printf("%128s", "Choose filling flavour(1-Chocolate, 2-Coconut, 3-Pandan, 4-Chicken, 5-Butter) : ");
      scanf("%d", &fillingflavour);

      switch(fillingflavour)
        {
        case 1 :
          printf("%92s","Enter number of unit for chocolate filling: ");
          scanf("%d", &numberflavour3);
          fillingtotal3 = (numberflavour1 * 1.20);
          break;

        case 2 :
          printf("%90s","Enter number of unit for coconut filling: ");
          scanf("%d", &numberflavour3);
          fillingtotal3 = (numberflavour1 * 1.50);
          break;

        case 3 :
          printf("%89s","Enter number of unit for pandan filling: ");
          scanf("%d", &numberflavour3);
          fillingtotal3 = (numberflavour1 * 1.00);
          break;

        case 4 :
          printf("%90s","Enter number of unit for chicken filling: ");
          scanf("%d", &numberflavour3);
          fillingtotal3 = (numberflavour1 * 1.75);
          break;

        case 5 :
          printf("%89s","Enter number of unit for butter filling: ");
          scanf("%d", &numberflavour3);
          fillingtotal3 = (numberflavour1 * 1.00);
          break;

        default :
          printf("%109s", "Your chosen flavour is not in the list. Please choose again.\n");
          goto chooseflavour3;


        }
      sum = (numberflavour1 + numberflavour2 + numberflavour3);
      if (sum > breadunit)
        printf("\n%144s", "Number of flavour chosen exceeded number of breads. Please enter correct amount of flavour unit\n");
      else if (sum == breadunit)
        goto subtotal;
      else if (sum < breadunit)
        goto choosefillingagain3;

      //Choose flavour again 3                    

    choosefillingagain3 : printf("%92s", "Do you want to add filling? [Y-Yes, N-No] : ");
      scanf("%c", &filling);
      filling = getchar();
      if (filling =='y')
        goto chooseflavour2;
      else if (filling =='Y')
        goto chooseflavour2;
      else if (filling == 'n')
        goto subtotal;
      else if (filling =='N')
        goto subtotal;
      else if (filling != 'y'||'Y'||'n'||'N')
        printf("%78s", "Please type either 'Y' or 'N'\n");
      goto choosefillingagain3;

    chooseflavour4 : printf("%128s", "Choose filling flavour(1-Chocolate, 2-Coconut, 3-Pandan, 4-Chicken, 5-Butter) : ");
      scanf("%d", &fillingflavour);

      switch(fillingflavour)
        {
        case 1 :
          printf("%92s","Enter number of unit for chocolate filling: ");
          scanf("%d", &numberflavour4);
          fillingtotal4 = (numberflavour1 * 1.20);
          break;

        case 2 :
          printf("%90s","Enter number of unit for coconut filling: ");
          scanf("%d", &numberflavour4);
          fillingtotal4 = (numberflavour1 * 1.50);
          break;

        case 3 :
          printf("%89s","Enter number of unit for pandan filling: ");
          scanf("%d", &numberflavour4);
          fillingtotal4 = (numberflavour1 * 1.00);
          break;

        case 4 :
          printf("%90s","Enter number of unit for chicken filling: ");
          scanf("%d", &numberflavour4);
          fillingtotal4 = (numberflavour1 * 1.75);
          break;

        case 5 :
          printf("%89s","Enter number of unit for butter filling: ");
          scanf("%d", &numberflavour4);
          fillingtotal4 = (numberflavour1 * 1.00);
          break;

        default :
          printf("%109s", "Your chosen flavour is not in the list. Please choose again.\n");
          goto chooseflavour4;


        }
      sum = (numberflavour1 + numberflavour2 + numberflavour3 + numberflavour4);
      if (sum > breadunit)
        printf("\n%144s", "Number of flavour chosen exceeded number of breads. Please enter correct amount of flavour unit\n");
      else if (sum == breadunit)
        goto subtotal;
      else if (sum < breadunit)
        goto choosefillingagain4; 

      //Choose flavour again 4

    choosefillingagain4 : printf("%92s", "Do you want to add filling? [Y-Yes, N-No] : ");
      scanf("%c", &filling);
      filling = getchar();
      if (filling =='y')
        goto chooseflavour2;
      else if (filling =='Y')
        goto chooseflavour2;
      else if (filling == 'n')
        goto subtotal;
      else if (filling =='N')
        goto subtotal;
      else if (filling != 'y'||'Y'||'n'||'N')
        printf("%78s", "Please type either 'Y' or 'N'\n");
      goto choosefillingagain4;

    chooseflavour5 : printf("%128s", "Choose filling flavour(1-Chocolate, 2-Coconut, 3-Pandan, 4-Chicken, 5-Butter) : ");
      scanf("%d", &fillingflavour);

      switch(fillingflavour)
        {
        case 1 :
          printf("%92s","Enter number of unit for chocolate filling: ");
          scanf("%d", &numberflavour5);
          fillingtotal5 = (numberflavour1 * 1.20);
          break;

        case 2 :
          printf("%90s","Enter number of unit for coconut filling: ");
          scanf("%d", &numberflavour5);
          fillingtotal5 = (numberflavour1 * 1.50);
          break;

        case 3 :
          printf("%89s","Enter number of unit for pandan filling: ");
          scanf("%d", &numberflavour5);
          fillingtotal5 = (numberflavour1 * 1.00);
          break;

        case 4 :
          printf("%90s","Enter number of unit for chicken filling: ");
          scanf("%d", &numberflavour5);
          fillingtotal5 = (numberflavour1 * 1.75);
          break;

        case 5 :
          printf("%89s","Enter number of unit for butter filling: ");
          scanf("%d", &numberflavour5);
          fillingtotal5 = (numberflavour1 * 1.00);
          break;

        default :
          printf("%109s", "Your chosen flavour is not in the list. Please choose again.\n");
          goto chooseflavour5;


        }
      sum = (numberflavour1 + numberflavour2 + numberflavour3 + numberflavour4 + numberflavour5);
      if (sum > breadunit)
        printf("\n%144s", "Number of flavour chosen exceeded number of breads. Please enter correct amount of flavour unit\n");
      else if (sum == breadunit)
        goto subtotal;
      else if (sum < breadunit)
        goto choosefillingagain5;

      //Choose flavour again 5

    choosefillingagain5 : printf("%92s", "Do you want to add filling? [Y-Yes, N-No] : ");
      scanf("%c", &filling);
      filling = getchar();
      if (filling =='y')
        goto chooseflavour2;
      else if (filling =='Y')
        goto chooseflavour2;
      else if (filling == 'n')
        goto subtotal;
      else if (filling =='N')
        goto subtotal;
      else if (filling != 'y'||'Y'||'n'||'N')
        printf("%78s", "Please type either 'Y' or 'N'\n");
      goto choosefillingagain5;

    chooseflavour6 : printf("%128s", "Choose filling flavour(1-Chocolate, 2-Coconut, 3-Pandan, 4-Chicken, 5-Butter) : ");
      scanf("%d", &fillingflavour);

      switch(fillingflavour)
        {
        case 1 :
          printf("%92s","Enter number of unit for chocolate filling: ");
          scanf("%d", &numberflavour6);
          fillingtotal6 = (numberflavour1 * 1.20);
          break;

        case 2 :
          printf("%90s","Enter number of unit for coconut filling: ");
          scanf("%d", &numberflavour6);
          fillingtotal6 = (numberflavour1 * 1.50);
          break;

        case 3 :
          printf("%89s","Enter number of unit for pandan filling: ");
          scanf("%d", &numberflavour6);
          fillingtotal6 = (numberflavour1 * 1.00);
          break;

        case 4 :
          printf("%90s","Enter number of unit for chicken filling: ");
          scanf("%d", &numberflavour6);
          fillingtotal6 = (numberflavour1 * 1.75);
          break;

        case 5 :
          printf("%89s","Enter number of unit for butter filling: ");
          scanf("%d", &numberflavour6);
          fillingtotal6 = (numberflavour1 * 1.00);
          break;

        default :
          printf("%109s", "Your chosen flavour is not in the list. Please choose again.\n");
          goto chooseflavour6;


        }
      sum = (numberflavour1 + numberflavour2 + numberflavour3 + numberflavour4 + numberflavour5 + numberflavour6);
      if (sum > breadunit)
        printf("\n%144s", "Number of flavour chosen exceeded number of breads. Please enter correct amount of flavour unit\n");
      else if (sum == breadunit)
        goto subtotal;

    subtotal : subtotal = ((breadtotal * breadunit) + fillingtotal1 + fillingtotal2 + fillingtotal3 + fillingtotal4 + fillingtotal5 + fillingtotal6);
      printf("\n                                                Subtotal #%d : RM %.2f \n",breadnum, subtotal); //2 decimal point

      breadnum++;

    }while (breadnum<=bread);
  printf("\n%162s","_________________________________________________________________________________________________________________\n");

  //Order summary details

  printf("\n%70s","Order Summary Details:");
  printf("\n                                                Total bread type ordered: %d\n",bread);

  breadnum=1;
  do
    {
      printf("\n                                                Bread type #%d : \n ",breadnum);
      switch(breadtype[breadnum])
    {
        case 1 :
          printf("%65s","Type : White loaf\n");
          break;

        case 2 :
          printf("%65s","Type : Wheat loaf\n");
          break;

        case 3 :
          printf("%58s","Type : Bun\n");
          break;

        case 4 :
          printf("%64s","Type : Croissant\n");
          break;
    }
      subtotal = ((breadtotal * breadunit) + fillingtotal1 + fillingtotal2 + fillingtotal3 + fillingtotal4 + fillingtotal5 + fillingtotal6);
      printf("\n                                                Subtotal #%d : RM %.2f \n",breadnum, subtotal);

      breadnum++;
    }while(breadnum<=bread);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.