Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- #include <conio.h>
- int main()
- {
- /* Declaracion de variables */
- int primerOperando = 0, segundoOperando = 0, operacion = 0, cantAciertos = 0,
- cantError = 0, cantOperaciones = 0, resultadoIngresadoInt = 0, resultadoRealInt = 0;
- float porcentaje = 0, resultadoIngresadoFloat = 0, resultadoRealFloat = 0;
- char seguir;
- do
- {
- srand(time(0));
- primerOperando = rand()%100 + 1;
- segundoOperando = rand()%100 + 1;
- operacion = rand()%4 + 1;
- cantOperaciones++;
- switch(operacion)
- {
- case 1:
- {
- printf("Realize la siguiente operacion %d + %d: ", primerOperando, segundoOperando);
- resultadoRealInt = primerOperando + segundoOperando;
- scanf("%d", &resultadoIngresadoInt);
- if(resultadoIngresadoInt == resultadoRealInt)
- {
- cantAciertos++;
- printf("Muy Bien \n");
- }
- else
- {
- cantError++;
- printf("Muy Mal\n");
- }
- }
- break;
- case 2:
- {
- printf("Realize la siguiente operacion %d - %d: ", primerOperando, segundoOperando);
- resultadoRealInt = primerOperando - segundoOperando;
- scanf("%d", &resultadoIngresadoInt);
- if(resultadoIngresadoInt == resultadoRealInt)
- {
- cantAciertos++;
- printf("Muy Bien \n");
- }
- else
- {
- cantError++;
- printf("Muy Mal\n");
- }
- }
- break;
- case 3:
- {
- printf("Realize la siguiente operacion %d * %d: ", primerOperando, segundoOperando);
- resultadoRealInt = primerOperando * segundoOperando;
- scanf("%d", &resultadoIngresadoInt);
- if(resultadoIngresadoInt == resultadoRealInt)
- {
- cantAciertos++;
- printf("Muy Bien \n");
- }
- else
- {
- cantError++;
- printf("Muy Mal\n");
- }
- }
- break;
- case 4:
- {
- printf("Realize la siguiente operacion %d / %d: ", primerOperando, segundoOperando);
- resultadoRealFloat = primerOperando / segundoOperando;
- scanf("%f", &resultadoIngresadoFloat);
- if(resultadoIngresadoFloat == resultadoRealFloat)
- {
- cantAciertos++;
- printf("Muy Bien \n");
- }
- else
- {
- cantError++;
- printf("Muy Mal\n");
- }
- }
- break;
- }
- printf("Quiere seguir jugando?(S/N): ");
- fflush(stdin); //Limpia el buffer de teclado
- scanf("%c", &seguir); //Ingresa la respuesta "S" para seguir ó "N" para terminar
- while(seguir != 's' && seguir != 'S' && seguir != 'n' && seguir != 'N') //Corrobora que solo ponga "s", "S", "n" ó "N". Si pone otra cosa repite el ciclo.
- {
- printf("Error, debe ingresar S/N. Desea seguir jugando?: ");
- fflush(stdin); //Limpia el buffer de teclado
- scanf("%c", &seguir); //Ingresa la respuesta "S" para seguir ó "N" para terminar, si pone cualquier otra cosa no sale del ciclo.
- }
- }while(seguir == 's' || seguir == 'S'); //Elecuta el ciclo do - while mientras el usuario desee seguir.
- printf("La cantidad de aciertos fue: %d \n", cantAciertos);
- printf("La cantidad de errores fue: %d \n", cantError);
- porcentaje = (cantAciertos * 100)/cantOperaciones;
- if(porcentaje == 100)
- printf("EXELENTE");
- if(porcentaje < 100 && porcentaje >= 80)
- printf("MUY BUENO");
- if(porcentaje < 80 && porcentaje >= 60)
- printf("BUENO");
- if(porcentaje < 60 && porcentaje >= 40)
- printf("REGULAR");
- if(porcentaje < 40)
- printf("MALO");
- getche();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment