Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
September 8th, 2013, 09:52 PM
 csisock
Registered User

Join Date: Sep 2013
Posts: 2
Time spent in forums: 3 h 30 m 2 sec
Reputation Power: 0
Can't figure out what's wrong with my Random Number Generator in C

Code:
```#include <stdio.h>
#include <stdlib.h>

#define MAX_VALUE = 6;
#define MIN_VALUE = 1;
const int NUMBER_OF_VALUES =(6 - 1 + 1);
const int NUMBER_OF_TRIALS = 1000;

int main()
{
int count[NUMBER_OF_VALUES];
int i;
int value = i + MIN_VALUE;
for (i=0;i<NUMBER_OF_TRIALS;i++)
{
int position;
int random;
double randomReal;
randomReal = rand()/(((double)RAND_MAX)+1)) * NUMBER_OF_VALUES + MIN_VALUE;
random = (int)(randomReal);
position = random - MIN_VALUE;
count[position] = count[position]+1;
}
printf("Counts\n");
for (i=0;i<NUMBER_OF_VALUES;i++)
{
printf("%d : %d\n",(value), count[i]);
}
int expectedCount;
expectedCount = NUMBER_OF_TRIALS/NUMBER_OF_VALUES;
printf("The expected count is %d\n",expectedCount);
printf("Distance From Average\n");
for (i=0;i<NUMBER_OF_VALUES;i++)
{
int distanceFromExpected;
distanceFromExpected = count[i] - NUMBER_OF_TRIALS/NUMBER_OF_VALUES;
printf("%d : %d\n",(value),abs(distanceFromExpected));
}
}
```

Every time I try to run it, I get these errors:

Code:
```**** Build of configuration Release for project RandomNumberCheckerInC ****

make all
Building target: RandomNumberCheckerInC
gcc  -o"RandomNumberCheckerInC"  ./randomNumberChecker.o
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 8 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 9 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 10 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 19 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 20 has invalid symbol index 20
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [RandomNumberCheckerInC] Error 1```

Which I figure to mean that there's no main method but I clearly have a main method in my program. I'm just a beginner C programmer using Eclipse to build and run my code. Why won't my current code work correctly?

#2
September 9th, 2013, 01:11 AM
 salem
Contributed User

Join Date: Jun 2005
Posts: 4,253
Time spent in forums: 2 Months 4 Weeks 1 Day 12 h 35 m 29 sec
Reputation Power: 1809
Well it doesn't even compile, so forget about linker error messages for the moment.

> #define MAX_VALUE = 6;
> #define MIN_VALUE = 1;

Change this to either
#define MAX_VALUE 6
#define MIN_VALUE 1

or this
const int MAX_VALUE = 6;
const int MIN_VALUE = 1;

EDIT
Nevermind, it's over here as well (another wasted post)
http://cboard.cprogramming.com/c-pr...tml#post1176767
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Last edited by salem : September 9th, 2013 at 02:07 AM.

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Can't figure out what's wrong with my Random Number Generator in C