Examen

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
tetos43
Date:
Fri Sep 13 17:39:04 2019 +0000
Parent:
0:f680c41c1640
Commit message:
Programa Adivina modificado como ejercicio de Examen

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Sep 05 23:29:04 2019 +0000
+++ b/main.cpp	Fri Sep 13 17:39:04 2019 +0000
@@ -1,6 +1,6 @@
 /* ###########################################################################
 **    Archivo        : main.c
-**    Proyecto       : STM32-103C8_Adivina
+**    Proyecto       : STM32-103C8_Adivina_Examen
 **    Procesador     : STM32F103C8
 **    Herramienta    : Mbed
 **    Version        : Driver 01.01
@@ -15,13 +15,14 @@
 **   Autores         :
 **         ATEAM Development Group:
 **          - Antulio Morgado Valle
+**          - Héctor Rodríguez Altamirano
 **
 **   Versión        : Beta
 **   Revisión       : A
 **   Release        : 0
 **   Bugs & Fixes   :
 **   Date           : 20/10/2019
-**                    Ejemplpo del Hola Mundo
+**                    Programa adivina Modificado para examen
 **                    27/09/2010 
 **                    
 **
@@ -36,6 +37,8 @@
 #include "mbed.h"
 #include "Serial.h"
 #include "stdio.h"
+#include "iostream" //Para usar cout
+//#include "stdlib.h"
 /*
 :...............................................................................
 :  Definiciones
@@ -71,6 +74,7 @@
 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */
 void Setup(void);  
+void portada(void);
 /* END definitions */ 
 
 /*
@@ -84,18 +88,31 @@
 {                   // Inicialización de variables, puertos e interrupciones
 confSysClock();     // Configure system clock (72MHz HSE clock, 48MHz USB clock)
 Setup();            // Inicialización del sistema
+    portada();
     terminal.printf ("ADIVINA\n\r");
     rojo  = off;
     verde = off;
-
+    int intentos=0;
+    char secreto;
     while(TRUE) 
     {
-Inicio:     terminal.printf(" DIGITE UN NUMERO SECRETO DE 0 A 9 \r\n");
-            char secreto = terminal.getc();
-            rojo = on;
-            verde = on;          
- Intenta:   terminal.printf(" ADIVINA EL NUMERO: \r\n");
+Inicio:     /*******************************************************************
+               do{
+               terminal.printf(" DIGITE UN NUMERO SECRETO DE 0 A 9 \r\n");
+               secreto = terminal.getc();
+               rojo = on;
+               verde = on;          
+               }while(secreto < '0' || secreto > '9');
+               Codigo de la version anterioe en la cual el numero secreto era
+               introducido por el usuario
+               ****************************************************************/
+            secreto=rand()%10+48; //Genera un numero aleatorio
+            terminal.printf("SE GENERO UN NUMERO SECRETO ALEATORIO \r\n");
+ Intenta:   intentos++;
+            terminal.printf(" INTENTO NUMERO %d \r\n",intentos);
+            terminal.printf(" ADIVINA EL NUMERO: \r\n");
             char respuesta = terminal.getc();
+            terminal.printf(" Tu respuesta es: %c \r\n",respuesta);
             if( secreto < respuesta  ) 
             {
                 terminal.printf(" Es mas Bajo  \r\n");
@@ -112,6 +129,7 @@
             }
             if( secreto == respuesta ) 
             {
+                intentos=0;
                 terminal.printf(" CORRECTO!, Es igual a: %c \r\n",secreto);
                 rojo  = off;
                 verde = on;
@@ -165,6 +183,17 @@
   terminal.printf(" System is Wake Up!.\n\r");
 }              
 
+void portada(void) // Implementacion de la portada
+{
+    //cout necesita la biblioteca "iostream"
+    cout << "\t\t\t\t\t\tISTITUTO POLITECNICO NACIONAL\n\n\n";
+    cout << "\t\t\t\t ESCUELA SUPERIOR DE INGENIERIA MECNICA Y "
+         << "ELECTRICA\n\n\n";
+    cout << "\t\t\t\t\tEXAMEN DE ANALISIS NUMERICO\n\n\n";
+    cout << "\t\t\t\t\tPROFESOR: MORGADO VALLE ANTULIO\n\n\n";
+    cout << "\t\t\t\t\tALUMNO: RODRIGUEZ ALTAMIRANO HECTOR"
+         << "\n\n\n\n\n" << endl;
+}
 /* END routines */   
  
 /* END program */