0

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);
  }

}
chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
Hopelessdecoy
  • 119
  • 1
  • 2
  • 10

3 Answers3

1

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!

Hopelessdecoy
  • 119
  • 1
  • 2
  • 10
0

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;

ThisaruG
  • 3,222
  • 7
  • 38
  • 60
  • Although using type `int` may not meet the needs of OP, code can certainly "assign a float or double value to an int variable" and get the truncated result – chux - Reinstate Monica Sep 23 '14 at 23:11
  • These errors occurred after changing it to double: Error 1 error C2296: '%' : illegal, left operand has type 'double' f:\hopelessarts\utilities\coinflip\coinflip\coin.c IntelliSense: expression must have integral or unscoped enum type f:\HopelessArts\UTILITIES\coinFlip\coinFlip\coin.c 18 7 coinFlip – Hopelessdecoy Sep 23 '14 at 23:14
  • you have trouble of generating random numbers...... You can't use % with double or float numbers. It only works with ints. My opinion is try a new method to generate random numbers. Like rand(); – ThisaruG Sep 23 '14 at 23:17
  • ok I will have to look up how to impliment rand, we talked about it in class but I was unsure how to use it... so I wrote this to be semi random. – Hopelessdecoy Sep 23 '14 at 23:28
  • You can generate a random number in various ways. (But not a lot). But It's you work right. You have to do it. It's not a good practice to give the code the OP needed as some of them may post there homework here, to someone else to do ! – ThisaruG Sep 23 '14 at 23:48
0

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().

Can_of_awe
  • 1,431
  • 1
  • 11
  • 17