Like Tree1Likes
  • 1 Post By laserlight

Spot the syntax error

This is a discussion on Spot the syntax error within the C Programming forums, part of the General Programming Boards category; I can not, for the life of me, find the syntax error. My compiler says it occurs at "void show(PRODUCTS ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    2

    Spot the syntax error

    I can not, for the life of me, find the syntax error. My compiler says it occurs at "void show(PRODUCTS rec);" before "rec". Also, can anyone tell me why my report function does not work correctly?

    Code:
    /*=================================*/
    /*                                 */
    /*       Kristopher Johnson        */
    /*             Lab 10              */
    /*    Bloodshed Dev-C++ 4.9.9.2    */
    /*            11/27/11             */
    /*                                 */
    /*=================================*/
    
    
    #include <stdio.h>
    #include <string.h>
    #define COMPANY "Sierra Sporting Goods"
    #define TRUE 1
    #define FALSE 0
    
    
    int     quit();
    int     menu();
    int     prompt(char *msg);
    int     getint(int min, int max, char *item);
    void    add();
    void    report();
    void    title(char *name);
    void    message(char *msg);
    void    strcase(char *desc);
    void    getstring(char *desc);
    void    init_costs(double *c, int x);
    void    show_costs(double *c, int x);
    void    show(PRODUCTS rec);
    double  total(int q, double c);
    double  profit(double p, double c, int q);
    double  getreal(double min, double max, char *item);
    char    dept[6][15] = {"", "Camping   ", "Tennis    ", "Golf      ",
                               "Snow Sports", "Water Sports"};
    typedef struct
         {
         int number, type, quantity;
         double cost, price, totalcost, totalprice;
         char desc[20];
         }PRODUCTS;
    
    
    /* ========================================================================== */
    main()
         {
         int choice, more = TRUE;
         do
              {
              choice = menu();
              switch (choice)
                   {       
                   case 1: add(); break;
                   case 2: report(); break;
                   case 3: message("\n\tInvalid selection"); break;
                   case 4: message("\n\tInvalid selection"); break;
                   case 5: more = quit(); break;
                   }
              }
         while (more);
         return 0;
         }
    /* ========================================================================== */
    int menu()
         {
         int choice;
         title(COMPANY);
         printf("\t1 = Add a record\n");
         printf("\t2 = Report a record\n");
         printf("\t3 = Delete a record\n");
         printf("\t4 = Change a record\n");
         printf("\t5 = Quit\n");
         choice = getint(1,5,"selection");
         return choice;
         }
    /* ========================================================================== */
    void add()
         {
         int choice, MINN, MAXN, MINT, MAXT, MINQ, MAXQ;
         double c[6], MINC, MAXC, MINP, MAXP;
         init_costs(c, 6);
         PRODUCTS rec;
         
         FILE *f;
         f = fopen("limits.txt", "r");
         if (f == NULL)
              {
              printf("\n\tError opening limits.txt!\n");
              return;
              }
         fscanf(f, "%d%d%d%d%d%d%lf%lf%lf%lf", &MINN, &MAXN, &MINT, &MAXT, &MINQ,
                                       &MAXQ, &MINC, &MAXC, &MINP, &MAXP) != EOF;
         fclose(f);
         
         FILE *fp;
         fp = fopen("PRODUCTS.dat", "ab");
         if (fp == NULL)
              {
              printf("\n\tError opening PRODUCTS.dat!\n");
              return;
              }
              
         do
              {
              rec.number = getint(MINN, MAXN, "the product number");
              rec.type = getint(MINT, MAXT, "the product type");
              getstring(rec.desc);
              rec.quantity = getint(MINQ, MAXQ, "the quantity");
              rec.cost = getreal(MINC, MAXC, "the cost");
              rec.price = getreal(MINP, MAXP, "the price");
              rec.totalcost = total(rec.quantity, rec.cost);
              rec.totalprice = total(rec.quantity, rec.price);
              strcase(rec.desc);
              show(rec);
              fwrite(&rec, sizeof(rec), 1, fp);
              c[rec.type] += rec.totalcost;
              show_costs(c, 6);
              choice = prompt("Continue");
              }
         while (choice == 'Y' || choice == 'y');
         fclose(fp);
         quit();
         }
    /* ========================================================================== */
    void title (char *name)
         {
         printf("\n\n\t%s\n\n\n", COMPANY);
         }
    /* ========================================================================== */
    void show(PRODUCTS rec)
         {
         printf("\n\n\tThe product number is -------> %04d", rec.number);
         printf("\n\tThe product type is ---------> %d", rec.type);
         printf("\n\tThe product description is --> %s", rec.desc);
         printf("\n\tThe quantity is -------------> %d", rec.quantity);
         printf("\n\tThe cost is -----------------> %.2f", rec.cost);
         printf("\n\tThe price is ----------------> %.2f\n\n", rec.price);
         printf("\n\tThe total cost is -----------> %.2f\n", rec.totalcost);
         printf("\n\tThe total price is ----------> %.2f\n", rec.totalprice);
         message("\n\tDone");
         }
    /* ========================================================================== */
    int getint(int min, int max, char *item)
         {
         int x, i;
         double c[6];
         printf("\n\tEnter %s (%d-%d): ", item, min, max);
         scanf("%d%*c", &x, *c);
         while (x < min || x > max)
              {
              message("\n\tError, re-enter selection");
              printf("\n\tEnter %s (%d-%d): ", item, min, max);
              scanf("%d%*c", &x, *c);
              }
         return x;
         }
    /* ========================================================================== */
    double getreal(double min, double max, char *item)
         {
         double y, i, c[6];
         printf("\n\tEnter %s (%.2f-%.2f): ", item, min, max);
         scanf("%lf%*c", &y, *c);
         while (y < min || y > max)
              {
              message("\n\tError, re-enter selection");
              printf("\n\tEnter %s (%.2f-%.2f): ", item, min, max);
              scanf("%lf%*c", &y, *c);
              }
         return y;
         }
    /* ========================================================================== */
    void message(char *msg)
         {
         printf("%s (press Enter to continue)", msg);
         getchar();
         }
    /* ========================================================================== */
    int quit()
         {
         int z, more = TRUE;
         z = prompt("\n\tTerminate program");
         if (z == 'Y' || z == 'y')
              {
              system("cls");
              message("\n\tProgram terminated successfully");
              more = FALSE;
              }
         return more;
         }
    /* ========================================================================== */
    int prompt(char *msg)
         {
         int b;
         do
              {
              printf("\n\t%s (Y/N)?", msg);
              b = getchar();
              fflush(stdin);
              b = toupper(b);
              if (b != 'Y' && b != 'N')
                   {
                   printf("\n\tError, try Y or N only\n");
                   }
              }
         while (b != 'Y' && b != 'N');
         return (b);
         }
    /* ========================================================================== */
    double total(int q, double c)
         {
         return(q * c);
         }
    /* ========================================================================== */
    double profit(double p, double c, int q)
         {
         return((p - c) * q);
         }
    /* ========================================================================== */
    void init_costs(double *c, int x)
         {
         int i;
         for (i = 1; i < x; i++)
              {
              *(c+i) = 0;
              }
         }
    /* ========================================================================== */
    void show_costs(double *c, int x)
         {
         int i;
         printf("\n\n\n\tProduct Cost by Type\n");
         printf("\n\n\tType\tDepartment\tCost\n");
         printf("\t------------------------------");
         for (i = 1; i < x; i++)
             {
             printf("\n\t%d\t%s\t%.2f\n", i, *(dept+i), *(c+i));
             }
         printf("\n");
         }
    /* ========================================================================== */
    void getstring(char *desc)
         {
         printf("\n\tEnter the product description: ");
         gets(desc);
         }
    /* ========================================================================== */
    void strcase(char *desc)
         {
         int x = 1, i;
         for (i = 0; *(desc+i) != '\0'; i++)
              {
              *(desc+i) = tolower(*(desc+i));
              if (*(desc+i) == ' ')
                   {
                   x = 1;
                   i++;
                   }
              if (x == 1 && *(desc+i) >= 'a' && *(desc+i) <= 'z')
                   {
                   *(desc+i) = *(desc+i) - 32;
                   x = 0;
                   }
              }
         }
    /* ========================================================================== */
    void report()
         {
         double tprofit, gtprofit;
         PRODUCTS rec;
         FILE *fp;
         fp = fopen("PRODUCTS.dat", "rb");
         if (fp == NULL)
              {
              printf("\n\tError opening PRODUCTS.dat!\n");
              return;
              }
         printf("\n\tProd#\tType\tDescription\t\tQty\tCost\tPrice\tProfit\n");
         printf("\t===================================================");
         while (fread(&rec, sizeof(rec), 1, fp))
              {
              tprofit = profit(rec.price, rec.cost, rec.quantity);
              tprofit += gtprofit;
              printf("\n\t%04d\t%d\t%s\t\t%d\t%.2f\t%.2f\n", rec.number,
                        rec.type, rec.desc, rec.quantity, rec.cost, rec.price);
              }
         printf("\t===================================================");
         printf("\n\tTotal expected profit\t\t\t%.2f\n", gtprofit);
         fclose(fp);
         }
    /* ========================================================================== */

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,174
    Quote Originally Posted by ender6456
    My compiler says it occurs at "void show(PRODUCTS rec);" before "rec".
    Notice that your typedef that introduces the name PRODUCTS comes after that line.
    stahta01 likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    2
    Quote Originally Posted by laserlight View Post
    Notice that your typedef that introduces the name PRODUCTS comes after that line.
    Wow, I feel stupid. Not only is the error gone, but my report function is also working properly now. Thank you very much for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Spot the error
    By Chewbacca in forum C++ Programming
    Replies: 6
    Last Post: 09-08-2002, 08:33 AM
  2. spot the error
    By razza in forum C++ Programming
    Replies: 5
    Last Post: 08-01-2002, 10:21 AM
  3. can someone help spot the error
    By blight2c in forum C++ Programming
    Replies: 6
    Last Post: 04-07-2002, 01:29 PM
  4. Spot the error
    By Snoopy in forum C++ Programming
    Replies: 8
    Last Post: 01-19-2002, 10:56 PM
  5. Can anyone spot the error in my code
    By korbitz in forum C Programming
    Replies: 2
    Last Post: 01-05-2002, 02:05 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21