Reputation: 129
This is my program for making a coin flip simulator, this is for school so I have to use my own code. But I need help the idea is to multiply the variable coin by 3.3 and then rounding off the decimals checking if its odd or even and associating that with heads or tails but I keep getting this error:
(Error 2 error LNK1104: cannot open file 'gdi32.lib' F:\HopelessArts\UTILITIES\coinFlip\coinFlip\LINK coinFlip)
I have no Idea what this means... here is my syntax:
#include <stdio.h>
int main(void) {
//coin flip program 100x should be 50/50 heads tails
int coin;
int heads;
int tails;
int counter;
coin = 3;
heads = 0;
tails = 0;
for (counter = 0; counter < 100; counter++) {
coin = coin * 3.3;
if (coin % 2 == 0) {
heads++;
} else {
tails++;
}
printf("Heads, tails %d%d", heads, tails);
}
}
Upvotes: 0
Views: 15281
Reputation: 1556
There are many good suggestions above about improving the randomness of your generator, although it seems you have forgotten to specify the return value of the main() function. Add in:
return 0;
just before the last brace, and remove the "void" parameter for main().
Upvotes: 0
Reputation: 129
Hey all I fixed the library issue by installing(or re installing unsure) the windows sdk and I fixed my code using the rand function like this:
#include <stdio.h>
#include <stdlib.h>
int main() {
//coin flip program 100x should be about 50/50 heads tails
int coin;
int heads;
int tails;
int counter;
heads = 0;
tails = 0;
for (counter = 0; counter < 100; counter++){
coin = rand();
if (coin%2 == 0 ){
heads++;
}
else{
tails++;
}
printf("%d,%d ", heads, tails);
}
printf("listed heads first then tails.");
system("pause");
}
Thanks for all the input! I will research all of your answers though to become a better programmer!
Upvotes: 1
Reputation: 3412
You can't assign a float
or double
value to an int
variable as you've done
coin = coin * 3.3;
Try to change int coin;
to double coin;
Upvotes: 0