For Loops Not Valid ?

My for loops seem valid but the compiler said otherwise

the goal of the program is print out the result of sales of each worker via for loops . What am I missing ?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

#include <stdio.h>
#include <stdlib.h>

#define EMPLOYEES 4
#define PRODUCTS 6
#define LIST 5

int main(void)
{

     int CompanyOweMoneyArray[EMPLOYEES][PRODUCTS] = {{0}};
     int CompanyDisplayAmount [EMPLOYEES][PRODUCTS] = {{0}} ;
     int ProductsValue[LIST] = { 20 , 10 , 5 , 2 , 1 };

     int EmployeesDataInput =0;
     int ProductsDataInput =0;

     int Edi = 0;
     int Pdi = 0;

     printf(" Welcome user! to the employees commission calculator \n\n");

     printf(" ---------------------------------------------------------\n");

     printf(" Have all infomation ready to input when asked ! \n\n");
     printf(" When done inputing your sales data just type in \"-1 -1\" \n\n");
     printf(" Look at table below for product code and price \n\n");

     printf(" (1) bicycle  - $20\n\n") ;
     printf(" (2) unicycle - $10\n\n") ;
     printf(" (3) tire     - $5\n\n") ;
     printf(" (4) pump     - $2\n\n") ;
     printf(" (5) chain    - $1\n\n") ;



     do{

            printf(" Please put in following e.x (2 4 ) if you want to end input type \"-1 -1\" \n\n");
            printf(" Valid Employee Number start from 1 and end at %i \n\n" , EMPLOYEES );
            printf(" Valid Product Number start from 1 and end at %i \n\n" , PRODUCTS -1 );
            printf(" Employee Number : Product Number :  ");
            scanf (" %i %i" , &EmployeesDataInput ,&ProductsDataInput);
            printf(" ---------------------------------------------------------\n");

            EmployeesDataInput = EmployeesDataInput -1 ;
            ProductsDataInput = ProductsDataInput - 1;


            Edi = EmployeesDataInput ;
            Pdi = ProductsDataInput ;


            for(Edi ; Edi < EMPLOYEES ; Edi++)
            {
                for(Pdi ; Pdi < PRODUCTS ; Pdi++ )
                {
                    CompanyDisplayAmount [Edi][Pdi] = CompanyOweMoneyArray [Edi][Pdi]+ ProductsValue[Pdi];
                }
            }


        }while(EmployeesDataInput !=-2 && ProductsDataInput != -2 );

            int ec = 0 ;
            int sum = 5 ;

                for (ec ; ec < EMPLOYEES ; ec++  )
                {
                    printf(" Here the amount the company owes Employee : %i Total : %i \n\n" , ec+1 , CompanyDisplayAmount [ec][sum]);
                }


      return 0;
}











closed account (DSLq5Di1)
1
2
#define PRODUCTS 6
#define LIST 5 

1
2
3
4
5
6
7
8
9
10
int ProductsValue[LIST] = { 20 , 10 , 5 , 2 , 1 };
...

            for(Edi ; Edi < EMPLOYEES ; Edi++)
            {
                for(Pdi ; Pdi < PRODUCTS ; Pdi++ )
                {
                    CompanyDisplayAmount [Edi][Pdi] = CompanyOweMoneyArray [Edi][Pdi]+ ProductsValue[Pdi];
                }
            }
Thanks for help really! but I'm not sure what you mean by bold things you put ?

If I remove Edi , Pdi it does remove the error "Warning : Statement with no effect" on both of the loops .

When it comes to the preprocessor constant List on Line 1 my goal was to put a value that would change in a instance.

Line 6 Pdi is the value the user puts in at start of program and its compared to PRODUCTS the second for loop

Line 8

CompanyDisplayAmount [Edi][Pdi] = CompanyOweMoneyArray [Edi][Pdi]+ ProductsValue[Pdi];

Goal was to add the arrays as variables

Total[r][c] = array 1 [r][c ] + array 2 (from predefine table)

since array are variables just with more memory locations.

Just showing you my thought process

Hmmm...

When I put a printf statement within the nested for loop it doesn't show either .

When I look at this statement closely

CompanyDisplayAmount [Edi][Pdi] = CompanyOweMoneyArray [Edi][Pdi]+ ProductsValue[Pdi];

Are you trying to say where is it being stored ?

I just thought it was a valid statement

example

CompanyDisplayAmount [0][1] = CompanyOweMoneyArray [0][1]+ ProductsValue[1];

20 = 0 + 20 ;

next round

CompanyDisplayAmount [0][1] = CompanyOweMoneyArray [0][1]+ ProductsValue[1];

40 = 20 + 20 ;

I cant see the issue :/


closed account (DSLq5Di1)
Sorry, I was very lazy with my reply.

ProductsValue is an array of 5 values and has indices 0, 1, 2, 3, 4. The inner for loop increments Pdi while it is less than 6. When Pdi == 5, ProductsValue[Pdi] will cause an out of range runtime error.
Topic archived. No new replies allowed.