Hinamarth

Farmville

Dec 11th, 2011
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.83 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<math.h>
  4.  
  5. void tab( int[]);
  6.  
  7. void tab( int plants[]){
  8.   int z, x, y, d, c;
  9.   x=lrand48()%10000;
  10.   y=lrand48()%10000;
  11.   if(x>=5000 && ((y>=1000 && y<=1010)||(y>=1020 && y<=1030))){
  12.     z=1;
  13.   }
  14.   else{ z=0; }
  15.   if(z==1){
  16.     for(c=0; c<=5000; c=(c+10)){
  17.       if(y>=1000 && y<=1010){
  18.     if(x>=(c+5000) && x<(c+5010)){
  19.       plants[(c/10)]++;
  20.     }
  21.       }
  22.       else{
  23.     if(x>=(c+5000) && x<(c+5010)){
  24.       plants[((c/10)+500)]++;
  25.     }
  26.       }
  27.     }
  28.   }
  29. }
  30.  
  31. main(){
  32.   int  i, g, plants[1000];
  33.   float cont, y, d;
  34.   FILE *fp;
  35.   srand48(time(0));
  36.   printf("Una grandine ha colpito il terreno dello Zio Tom! Fortunatamente, in 100 mq, lo Zio ha piantanto solo due file di fragole, ognuna da 500 piante ciascuna. \n");
  37.   printf("Il programma cercherà di aiutare Tom a prevedere i danni che subiranno le piante al variare della quantità di grandine caduta.\n");
  38.   printf("Inserisci quindi il numero di chicchi di grandine:\n g = ");
  39.   scanf("%d", &g);
  40.   while(g<0){
  41.     printf("Non puoi mettere un numero negativo! Suvvia, aiutiamo lo Zio Tom!\n g = ");
  42.     scanf("%d", &g);
  43.   }
  44.   for(i=0; i<1000; i++){
  45.     plants[i]=0;
  46.   }
  47.   for(i=0; i<g; i++){
  48.     tab( plants);
  49.   }
  50.   for(i=0; i<1000; i++){
  51.     if(plants[i]>=3){
  52.       cont++;
  53.     }
  54.   }
  55.   printf("Le piante distrutte sono:\n %f %%", (float)cont/10);
  56.   printf("\n");
  57.   if((fp=fopen("fragole.dat", "w"))==NULL){
  58.     printf("Errore nell'apertura del file fragole.dat\n");
  59.     exit(EXIT_FAILURE);
  60.   }
  61.   fprintf(fp, "Le piante distrutte sono:\n");
  62.   fprintf(fp, "\n");
  63.   for(i=0; i<1000; i++){
  64.     d=i;
  65.     if(plants[i]>=3){
  66.       if(i>=0 && i<501){
  67.     y=10.0;
  68.     fprintf(fp, "%d - ( %f , %f )\n", i, ((d/10)+50), y);
  69.       }
  70.       else{
  71.     y=10.2;
  72.     fprintf(fp, "%d - ( %f , %f )\n", i, (((d-501)/10)+50), y);
  73.       }
  74.     }
  75.   }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment