Hey all,
I am new to C programming and I have written this small program to work out this maths problem our teacher gave to us (and yes she said i could write a prog to work it out) and i think i've got the right idea, except that in the 2 places in an if and else i have statements to assign values to array elements, the compiler gives warnings saying "Code has no affect" or somehting like that, and thus the element's aren't getting their values assigned. When i run the program it gives me a error window to either ignore or close.
Any help shall be much appreciated.
Heres the code:
===start code===
#include <stdio.h>
/* These are the libary function files to be included*/
#include <stdlib.h>
#define LOCKERS 1000
/* Defines constants */
#define STUDENTS 1000
int loop_num;
/*Defines variables*/
int lockers[1002];
/* Defines array*/
void calc_locker_num(int student);
/* Function prototypes*/
void change_state(int num); /* another function*/
int loop2; /* variable*/
main()
{
puts("Welcome, this program will calculate the maths problem");
/* writing a bit of info on screen*/
puts("and then display the results on screen");
getchar();
/* more info*/
/*loop to assign all array elements in lockers[] to 1 (open)*/
for(loop2 = 0; lockers[loop2] != 1 && loop2 <= 1000; loop2++)
{
lockers[loop2] = 1;
}
/* cycles through the students and then sends info to function calc_locker_num()*/
for(loop_num = 1; loop_num <= 1000; loop_num++)
{
calc_locker_num(loop_num);
}
return 0;
}
void calc_locker_num(int student)
{
int locker_loop = 1;
for (; locker_loop % student == 0 && locker_loop <= 1000; locker_loop++)
{
change_state(locker_loop);
}
}
void change_state(int num)
{
if ( lockers[num] == 1 )
{
lockers[num] == 2; /* compiler moaning about this one*/
}
else
{
lockers[num] == 1; /* and this one*/
}
printf("\n Locker number %d is open1 closed 2: %d " , num, lockers[num] );
}
===End Code===
please excuse if it is in bad style;P im a newbe.
-SaRdIeN