TheMalva

Ejercicio1-Parcial2005

Jun 26th, 2013
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.39 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5.  
  6. int main()
  7. {
  8.     /* Declaracion de variables */
  9.     int primerOperando = 0, segundoOperando = 0, operacion = 0, cantAciertos = 0,
  10.         cantError = 0, cantOperaciones = 0, resultadoIngresadoInt = 0, resultadoRealInt = 0;
  11.     float porcentaje = 0, resultadoIngresadoFloat = 0, resultadoRealFloat = 0;
  12.     char seguir;
  13.    
  14.     do
  15.     {
  16.         srand(time(0));
  17.         primerOperando = rand()%100 + 1;
  18.         segundoOperando = rand()%100 + 1;
  19.         operacion = rand()%4 + 1;
  20.         cantOperaciones++;
  21.        
  22.         switch(operacion)
  23.         {
  24.             case 1:
  25.             {
  26.                 printf("Realize la siguiente operacion %d + %d: ", primerOperando, segundoOperando);
  27.                 resultadoRealInt = primerOperando + segundoOperando;
  28.                 scanf("%d", &resultadoIngresadoInt);
  29.                 if(resultadoIngresadoInt == resultadoRealInt)
  30.                 {
  31.                     cantAciertos++;
  32.                     printf("Muy Bien \n");
  33.                 }
  34.                 else
  35.                 {
  36.                     cantError++;
  37.                     printf("Muy Mal\n");
  38.                 }
  39.             }
  40.             break;
  41.            
  42.             case 2:
  43.             {
  44.                 printf("Realize la siguiente operacion %d - %d: ", primerOperando, segundoOperando);
  45.                 resultadoRealInt = primerOperando - segundoOperando;
  46.                 scanf("%d", &resultadoIngresadoInt);
  47.                 if(resultadoIngresadoInt == resultadoRealInt)
  48.                 {
  49.                     cantAciertos++;
  50.                     printf("Muy Bien \n");
  51.                 }
  52.                 else
  53.                 {
  54.                     cantError++;
  55.                     printf("Muy Mal\n");
  56.                 }
  57.             }
  58.             break;
  59.            
  60.             case 3:
  61.             {
  62.                 printf("Realize la siguiente operacion %d * %d: ", primerOperando, segundoOperando);
  63.                 resultadoRealInt = primerOperando * segundoOperando;
  64.                 scanf("%d", &resultadoIngresadoInt);
  65.                 if(resultadoIngresadoInt == resultadoRealInt)
  66.                 {
  67.                     cantAciertos++;
  68.                     printf("Muy Bien \n");
  69.                 }
  70.                 else
  71.                 {
  72.                     cantError++;
  73.                     printf("Muy Mal\n");
  74.                 }
  75.             }
  76.             break;
  77.            
  78.             case 4:
  79.             {
  80.                 printf("Realize la siguiente operacion %d / %d: ", primerOperando, segundoOperando);
  81.                 resultadoRealFloat = primerOperando / segundoOperando;
  82.                 scanf("%f", &resultadoIngresadoFloat);
  83.                 if(resultadoIngresadoFloat == resultadoRealFloat)
  84.                 {
  85.                     cantAciertos++;
  86.                     printf("Muy Bien \n");
  87.                 }
  88.                 else
  89.                 {
  90.                     cantError++;
  91.                     printf("Muy Mal\n");
  92.                 }
  93.             }
  94.             break;
  95.         }
  96.        
  97.         printf("Quiere seguir jugando?(S/N): ");
  98.         fflush(stdin); //Limpia el buffer de teclado
  99.         scanf("%c", &seguir); //Ingresa la respuesta "S" para seguir ó "N" para terminar
  100.        
  101.         while(seguir != 's' && seguir != 'S' && seguir != 'n' && seguir != 'N') //Corrobora que solo ponga "s", "S", "n" ó "N". Si pone otra cosa repite el ciclo.
  102.         {
  103.             printf("Error, debe ingresar S/N. Desea seguir jugando?: ");
  104.             fflush(stdin); //Limpia el buffer de teclado
  105.             scanf("%c", &seguir); //Ingresa la respuesta "S" para seguir ó "N" para terminar, si pone cualquier otra cosa no sale del ciclo.
  106.         }
  107.        
  108.     }while(seguir == 's' || seguir == 'S'); //Elecuta el ciclo do - while mientras el usuario desee seguir.
  109.    
  110.     printf("La cantidad de aciertos fue: %d \n", cantAciertos);
  111.     printf("La cantidad de errores fue: %d \n", cantError);
  112.     porcentaje = (cantAciertos * 100)/cantOperaciones;
  113.     if(porcentaje == 100)
  114.         printf("EXELENTE");
  115.     if(porcentaje < 100 && porcentaje >= 80)
  116.         printf("MUY BUENO");
  117.     if(porcentaje < 80 && porcentaje >= 60)
  118.         printf("BUENO");
  119.     if(porcentaje < 60 && porcentaje >= 40)
  120.         printf("REGULAR");
  121.     if(porcentaje < 40)
  122.         printf("MALO");
  123.    
  124.     getche();
  125.     return 0;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment