Problem with arithmetic operand, used to work but now it doesn't.

This is a discussion on Problem with arithmetic operand, used to work but now it doesn't. within the C Programming forums, part of the General Programming Boards category; Hi. I'm having a problem with two lines of code. In my first program, those two lines compiled with no ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    12

    Problem with arithmetic operand, used to work but now it doesn't.

    Hi. I'm having a problem with two lines of code. In my first program, those two lines compiled with no problem. Now, as I redid the program to do arrays, now those two lines are giving me problems and I have not changed them. Here is my code with compile details. The offending lines are in main(), when I'm trying to multiply sale_comm.

    rohan% vi project4.c
    rohan% script output.out
    Script started, file is output.out
    rohan% cat project4.c

    Code:
    #define ZERO 0.0
    #define COMMISSION_RATE 0.144
    #define BONUS_COMM_RATE 0.188
    #define TRUE 1
    #define FALSE 0
    #define HIGH_SALESPERSON 7
    #define ARRAY_SIZ 75
    #include <stdio.h>
    int s_code[ARRAY_SIZ];
    int c_code[ARRAY_SIZ];
    double sale_amount[ARRAY_SIZ];
    double sale_comm[ARRAY_SIZ];
    int flag[ARRAY_SIZ];
    void input_fun();
    void output_fun();
    int sales_code();
    int cust_code();
    double sale();
    void comm_report (double comm, int bonus);
    void sale_error();
    
    main()
    {  int num_sales, n;
       double total_sales, total_comm;
          input_fun();
          for (n =0; n < num_sales; n++)
             if (sale_amount[n] > 1450)
             {
                flag[n] = TRUE;
                sale_comm[n] = (208.8 + ((sale_amount - 1450) * BONUS_COMM_RATE));
             }
             else
             {
                flag[n] = FALSE;
                sale_comm[n] = (sale_amount * COMMISSION_RATE);
             }
             total_sales += sale_amount[n];
             total_comm += sale_comm[n];
             s_code[n] = sales_code();
          output_fun();
    }
    
    
    void
    input_fun()
    {
       int n, num_sales;
       s_code[n] = sales_code();
       while (s_code[n] != ZERO)
       {
          if (s_code[n] <= HIGH_SALESPERSON && s_code[n] > ZERO)
          {
             c_code[n] = cust_code();
             sale_amount[n] = sale();
             num_sales += 1;
             n++;
          }
          else
          {
             sale_error();
             s_code[n] = sales_code();
          }
       }
       return;
    }
    
    void
    output_fun()
    {
       int n, num_sales, flag;
       printf("\n\n        SALES REPORT");
       printf("\n\nSP CUST      SALE         COMM");
       for (n = 0; n < num_sales; n++)
       {
          printf("%d %3d  $%9.2lf\n", &s_code[n], &c_code[n], &sale_amount[n]);
          if (flag == TRUE)
          {
             printf("**");
          }
          else
          {
             printf("  ");
          }
          printf("  $%9.2lf", &sale_comm[n]);
       }
       return;
    }
    
    
    
    int
    sales_code()
    {
       int sval;
       printf("\n\nSalesperson code (1-7)(Enter 0 to quit): ");
       scanf("%d", &sval);
          return sval;
    }
    
    int
    cust_code()
    {
       int cval;
       printf("Customer code: ");
       scanf("%d", &cval);
          return cval;
    }
    
    double
    sale()
    {
       double amount;
       printf("Sale amount in dollars and cents: ");
       scanf("%lf", &amount);
          return amount;
    }
    
    
    void
    sale_error()
    {
       printf("Salesperson code must be 1 to 7");
          return;
    }

    rohan% cc project4.c
    "project4.c", line 35: operands must have arithmetic type: op "*"
    "project4.c", line 40: operands must have arithmetic type: op "*"
    cc: acomp failed for project4.c
    Last edited by OmniMirror; 05-01-2003 at 12:32 PM.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,801
    sale_amount is an array but you are using it without the subscript/indexing you probably should be using for the following lines:
    Code:
    sale_comm[n] = (208.8 + ((sale_amount - 1450) * BONUS_COMM_RATE));
    sale_comm[n] = (sale_amount * COMMISSION_RATE);
    Just a guess, but maybe it should be this instead?:
    Code:
    sale_comm[n] = (208.8 + ((sale_amount[n] - 1450) * BONUS_COMM_RATE));
    sale_comm[n] = (sale_amount[n] * COMMISSION_RATE);
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    sale_comm[n] = (208.8 + ((sale_amount - 1450) * BONUS_COMM_RATE));
    sale_amount is an array, not a single variable.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    12
    That's it! Thanks for your help.

    Now I can work on debugging it, but that shouldn't be too bad.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  2. Problem with some arithmetic!
    By bobthebullet990 in forum C Programming
    Replies: 4
    Last Post: 01-05-2007, 09:04 AM
  3. I have problem!!!
    By Dragon227Slayer in forum C# Programming
    Replies: 9
    Last Post: 01-21-2004, 02:49 AM
  4. Replies: 5
    Last Post: 12-03-2003, 04:47 PM
  5. problem with the divisor
    By yusiye in forum C Programming
    Replies: 13
    Last Post: 08-01-2002, 01:30 PM

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