d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Fg For C Help > Due At Midnight
Add Reply New Topic New Poll
Member
Posts: 8,732
Joined: Nov 21 2007
Gold: 775.00
Sep 27 2013 06:18pm
A monte carlo assignment, no print statements are written yet

EDIT: Due at midnight, fg donations for help

basically to throw darts at a target on a rectangle thats 20x20 maxes=10 mins=-10 the target is a circle in the dead center centered at 0,0 witha radius of 3

getting various errors with vim

expected expression before 'double on the x = double y = double and those are my only errors, however when i delete the 'double' i get all these odd errors and my file gets deleted somehow

here it is

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159
#define RADIUS 3

int main (int argc, char *argv[])
{
int dNum, seed;
int recArea = 400;
int hits = 0;
int p = 0;
double x, y;
double xmin = -10, xmax = 10, ymin = 10, ymax = 10;
srand(seed);

printf("Enter the random number seed:\n");
scanf("%d", &seed);
printf("Enter the number of darts to throw:\n");
scanf("%d", &dNum);

void getBorders (double *xmin,double *xmax,double *ymin,double *ymax);

for (p=1; p<=dNum; p++) {
x = double RandNumInRange(*xmin, *xmax);
y = double RandNumInRange(*ymin, *ymax);
int DartHits(x,y);
if (DartHits(x,y) == 1) {
hits++;
}
}

double RandNumInRage(double minval, double maxval)
{
double value;
value = rand() / RAND_MAX * (2 * maxval) + minval;
return value;
}

int DartHits (double x, double y)
{
if (sqrt(x*x+y*y) <= RADIUS) {
return 1;
} else {
return 0;
}
}
return 0;
}

This post was edited by GODBAAL on Sep 27 2013 06:18pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 27 2013 06:24pm
if you're trying to cast, use (double)
Member
Posts: 8,732
Joined: Nov 21 2007
Gold: 775.00
Sep 27 2013 06:28pm
Quote (carteblanche @ Sep 27 2013 06:24pm)
if you're trying to cast, use (double)


x = (double) RandNumInRange(xmin, xmax);
y = (double) RandNumInRange(ymin, ymax);


I changed it to that and got


mcint.c: In function 'main':
mcint.c:28: warning: parameter names (without types) in function declaration
/usr/bin/ld: unrecognised emulation mode: cint.c
Supported emulations: elf_i386 i386linux elf_x86_64
collect2: ld returned 1 exit status

EDIT

now

/home/dlp902/courses/cs/1713/mcint.c:26: undefined reference to `RandNumInRange'
/home/dlp902/courses/cs/1713/mcint.c:27: undefined reference to `RandNumInRange'
/home/dlp902/courses/cs/1713/mcint.c:29: undefined reference to `DartHits'
/tmp/cc7DPHFu.o: In function `DartHits':
/home/dlp902/courses/cs/1713/mcint.c:43: undefined reference to `sqrt'
collect2: ld returned 1 exit status




This post was edited by GODBAAL on Sep 27 2013 06:51pm
Member
Posts: 11,610
Joined: Oct 28 2008
Gold: 1,795.00
Sep 27 2013 11:52pm
Quote (GODBAAL @ Sep 27 2013 07:28pm)
x = (double) RandNumInRange(xmin, xmax);
y = (double) RandNumInRange(ymin, ymax);


I changed it to that and got


mcint.c: In function 'main':
mcint.c:28: warning: parameter names (without types) in function declaration
/usr/bin/ld: unrecognised emulation mode: cint.c
Supported emulations: elf_i386 i386linux elf_x86_64
collect2: ld returned 1 exit status

EDIT

now

/home/dlp902/courses/cs/1713/mcint.c:26: undefined reference to `RandNumInRange'
/home/dlp902/courses/cs/1713/mcint.c:27: undefined reference to `RandNumInRange'
/home/dlp902/courses/cs/1713/mcint.c:29: undefined reference to `DartHits'
/tmp/cc7DPHFu.o: In function `DartHits':
/home/dlp902/courses/cs/1713/mcint.c:43: undefined reference to `sqrt'
collect2: ld returned 1 exit status


You're not defining your 'DarkHits' properly, also "RandNumInRange" is not a function

Look into
http://stackoverflow.com/questions/2999075/generate-a-random-number-within-range/2999130#2999130
and
http://stackoverflow.com/questions/288739/generate-random-numbers-uniformly-over-an-entire-range/288869#288869

This post was edited by 0n35 on Sep 27 2013 11:53pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll