Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. //
  2. // ruotaFortuna_structversion.c
  3. // poliTo
  4. //
  5. //
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <ctype.h>
  10. #include <string.h>
  11. #include <time.h>
  12. #define MAX_REG 20
  13. #define NUM 6
  14. #define NUM_RUOTE 20
  15.  
  16. typedef struct ruota{
  17. char nome[MAX_REG+1];
  18. int numeri[NUM];
  19. }Ruota;
  20.  
  21. void LeggiGiocata(int*);
  22. void GeneraRuota(Ruota*);
  23. int GiocaSuRuota (Ruota ruota ,int*);
  24.  
  25. int main(int argc, char *argv[]){
  26.  
  27. srand(time(NULL));
  28. if(argc != 2) {
  29. printf("Variabili mancanti");
  30. return -1;
  31. }
  32.  
  33.  
  34. int i;
  35. int n = atoi(argv[1]);
  36. int giocata[NUM];
  37.  
  38.  
  39. Ruota ruote[NUM_RUOTE];
  40.  
  41. // ==== ===== ======
  42.  
  43. for (i=0; i<n; i++) {
  44. GeneraRuota(&ruote[i]);
  45. }
  46.  
  47. LeggiGiocata(giocata);
  48.  
  49. for (i=0; i<n; i++) {
  50. int occ = GiocaSuRuota(ruote[i],giocata);
  51. if (occ) printf("Hai %d occorrenze sulla Ruota di %s\n\n", occ, ruote[i].nome);
  52. }
  53.  
  54. return 0;
  55. }
  56.  
  57.  
  58. void LeggiGiocata (int giocata[]) {
  59. int i;
  60. for (i=0; i<NUM; i++) {
  61. printf("Dammi valore giocata %d",i+1);
  62. scanf("%d",&giocata[i]);
  63. }
  64.  
  65. }
  66.  
  67.  
  68. void GeneraRuota(Ruota* ruota){
  69. printf("Dammi il nome della ruota");
  70. scanf("%s", ruota->nome);
  71. int i;
  72. for (i=0; i<NUM; i++) {
  73. ruota->numeri[i] = (rand() % 90) +1;
  74. }
  75. }
  76.  
  77. int GiocaSuRuota (Ruota ruota, int giocata []){
  78. int i,k;
  79. int cont =0;
  80.  
  81. for(i=0; i<NUM; i++){
  82. for(k=0; k<NUM; k++){
  83. if(giocata[i] == ruota.numeri[k]) cont++;
  84. }
  85. }
  86.  
  87. return cont;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement