Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ruotaFortuna_structversion.c
- // poliTo
- //
- //
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- #include <time.h>
- #define MAX_REG 20
- #define NUM 6
- #define NUM_RUOTE 20
- typedef struct ruota{
- char nome[MAX_REG+1];
- int numeri[NUM];
- }Ruota;
- void LeggiGiocata(int*);
- void GeneraRuota(Ruota*);
- int GiocaSuRuota (Ruota ruota ,int*);
- int main(int argc, char *argv[]){
- srand(time(NULL));
- if(argc != 2) {
- printf("Variabili mancanti");
- return -1;
- }
- int i;
- int n = atoi(argv[1]);
- int giocata[NUM];
- Ruota ruote[NUM_RUOTE];
- // ==== ===== ======
- for (i=0; i<n; i++) {
- GeneraRuota(&ruote[i]);
- }
- LeggiGiocata(giocata);
- for (i=0; i<n; i++) {
- int occ = GiocaSuRuota(ruote[i],giocata);
- if (occ) printf("Hai %d occorrenze sulla Ruota di %s\n\n", occ, ruote[i].nome);
- }
- return 0;
- }
- void LeggiGiocata (int giocata[]) {
- int i;
- for (i=0; i<NUM; i++) {
- printf("Dammi valore giocata %d",i+1);
- scanf("%d",&giocata[i]);
- }
- }
- void GeneraRuota(Ruota* ruota){
- printf("Dammi il nome della ruota");
- scanf("%s", ruota->nome);
- int i;
- for (i=0; i<NUM; i++) {
- ruota->numeri[i] = (rand() % 90) +1;
- }
- }
- int GiocaSuRuota (Ruota ruota, int giocata []){
- int i,k;
- int cont =0;
- for(i=0; i<NUM; i++){
- for(k=0; k<NUM; k++){
- if(giocata[i] == ruota.numeri[k]) cont++;
- }
- }
- return cont;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement