Código
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <ctype.h> void main() { srand(time(NULL)); int r, res, i; bool exit = false, ok; char retry; printf("JOC DE ENDEVINAR EL NUMERO\n\n"); do { r = (rand() % 10) + 1; i = 0; do{ printf("Introdueix un numero (1-10): "); /*-------------------------------------------*/ /*-------------------------------------------*/ /*-------------------------------------------*/ ok = scanf("%i", &res); /*-------------------------------------------*/ /*-------------------------------------------*/ /*-------------------------------------------*/ while (getchar() != '\n'); if (ok && res >= 1 && res <= 10 ) { if (res < r) { printf("Nº massa baix\n"); } else if (res > r) { printf("Nº massa alt\n"); } else if (res == r) { printf("Has encertat!\n"); exit = true; } i++; } else { printf("No has introduit un valor disponible\n"); } }while (i < 12 && exit == false ); printf("Intents realitzats: %d\n", i); exit = false; do{ printf("Vols tornar a jugar? (Y/N): "); scanf("%c", &retry); retry = towlower(retry); while (getchar() != '\n'); if (retry == 'n') { exit = true; } else if (retry == 'y') { } else { printf("Introdueix una opcioo vàlida\n"); } }while (retry != 'y' && retry != 'n'); } while (exit == false); system("pause"); }
Gracias por su ayuda.
Un saludo.