Yo había encontrado el siguiente ejemplo escrito en C en internet:<br><pre style="min-height:372px">------------------------------------------------------------------------------------------<br>/* Código creado por pax 2012 */
#include <stdio.h>
#include <conio.h>
int main(){
int not1, not2, not3, opt;
float prom;
a: /*Inicio*/
printf("Ingrese la nota del primer trimestre\n");
scanf("%d", ¬1);
if(not1 > 10)
{
printf("\nLa nota del trimestre tiene que ser igual o menor a 10\n\n");
goto a;
}
b:
printf("Ingrese la nota del segundo trimestre\n");
scanf("%d", ¬2);
if(not2 > 10)
{
printf("\nLa nota del trimestre tiene que ser igual o menor a 10\n\n");
goto b;
}
c:
printf("Ingrese la nota del tercer trimestre\n");
scanf("%d", ¬3);
if(not3 > 10)
{
printf("\nLa nota del trimestre tiene que ser igual o menor a 10\n\n");
goto c;
}
prom = (float) (not1 + not2 + not3) / 3;
printf("\n La nota final es: %.2f\n", prom);
if(prom >= 6)
{
printf("\nAPROBADO\n");
}
if(prom < 6 && prom >= 4)
{
printf("\nDICIEMBRE\n");
}
if(prom < 4)
{
printf("\nMARZO\n");
}
/* Continuar - Finalizar */
printf("\n\n¿Desea volver a operar?");
printf("\n1. Si");
printf("\n2. No\n");
scanf("%i",&opt);
if(opt == 1)goto a;
printf("\n\nPresione una tecla para cerrar el programa");
getch();
return 0;
}</pre><br><pre class="bbcode_code" style="height:372px">------------------------------------------------------------------------------------------<br><br><font face="arial,helvetica,sans-serif"><font>pero algo no me había convencido de este ejemplo, así que lo modifiqué un poco:<br>
<br></font></font>------------------------------------------------------------------------------------------<br>#include <stdio.h><br>#include <stdlib.h><br><br>#if defined (linux)<br>#define TERM_CLEAN "clear"<br>
#else <br>#define TERM_CLEAN "cls"<br>#endif<br><br>int resolver_promedio (void);<br><br>int main (void)<br>{<br> int init = resolver_promedio ();<br><br> system (TERM_CLEAN);<br><br> if (init == 1)<br> {<br> resolver_promedio ();<br>
}<br><br> printf("\n\nPresione una tecla para cerrar el programa");<br> getchar ();<br> getchar ();<br> return 0;<br>}<br><br>int resolver_promedio (void)<br>{<br> unsigned int nota1 = NULL, nota2 = NULL, nota3 = NULL, opcion, promedio;<br>
<br> do {<br> system (TERM_CLEAN);<br> printf ("Ingrese la nota del primer trimestre\nEl rango de notas es 0 - 10\n");<br> scanf ("%d", ¬a1);<br> } while (nota1 > 10);<br> <br> do {<br> system (TERM_CLEAN);<br>
printf ("Ingrese la nota del segundo trimestre\nEl rango de notas es 0 - 10\n");<br> scanf ("%d", ¬a2);<br> } while (nota2 > 10);<br><br> do {<br> system (TERM_CLEAN);<br> printf ("Ingrese la nota del tercer trimestre\nEl rango de notas es 0 - 10\n");<br>
scanf ("%d", ¬a3);<br> } while (nota3 > 10);<br><br> system (TERM_CLEAN);<br> promedio = ((nota1 + nota2 + nota3) / (3));<br><br> if (promedio >= 6)<br> printf ("\nPromedio anual %d\tAPROBADO\n", promedio);<br>
else if ((promedio < 6) && (promedio >= 4))<br> printf ("\nPromedio anual %d\tEXAMEN DICIEMBRE\n", promedio);<br> else if (promedio < 4)<br> printf ("\nPromedio anual %d\tEXAMEN MARZO\n", promedio);<br>
<br> printf("\n\n¿Desea calcular otros promedios anuales?"<br> "\n1. Si"<br> "\n0. No\n");<br> scanf("%i", &opcion);<br> if (opcion == 1)<br> return 1;<br> <br> return 0;<br>
}<br><br><br>------------------------------------------------------------------------------------------<br><br><span style="font-family:arial,helvetica,sans-serif"><font>¿Qué les parece? ¿En qué podría estar fallando el ejemplo original y el ejemplo modificado por mí?</font> <font>¿Tienen alguna recomendacion que quieran hacerme?</font></span><br>
</pre>