Revision: 59448
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at September 8, 2012 08:54 by OdnetninI
Initial Code
// Includes of the System #include <stdio.h> #include <inttypes.h> // Float variables of numbers float a = 0; float b = 0; // Float variable of result float result = 0; // Check Variable uint8_t lastresult = 0; /* Fuction AskNumbers Ask for the numbers */ void AskNumbers () { if (lastresult == 0 ) { printf("Elige el primer N���ºmero: "); scanf("%f", &a); printf("Elige el segundo N���ºmero: "); scanf("%f", &b); } else if (lastresult == 1) { a = result; printf("Elige el segundo N���ºmero: "); scanf("%f", &b); } else if (lastresult == 2) { b = result; printf("Elige el Primer N���ºmero: "); scanf("%f", &a); } } /* Fuction PrintfOptions Printf the Options */ void PrintfOptions () { printf("Basic Calculador by OdnetninI\n"); printf("-----------------------------\n"); printf("1. Suma\n"); printf("2. Resta\n"); printf("3. Multiplicaci���³n\n"); printf("4. Divisi���³n\n"); printf("5. Potencia\n"); printf("-----------------------------\n"); } /* Main Init point of System */ int main() { // Temporal vairables uint8_t salir = 0; uint8_t opcion = 0; // Main While while(salir == 0) { // Printf the Options PrintfOptions(); // Ask for the option printf("Elija su Opci���³n: "); scanf("%d", &opcion); // Check if answer is correct if (opcion > 0 && opcion < 6) AskNumbers(); // Make the operation switch (opcion) { case 1: printf("%5.2f + %5.2f = %5.2f\n", a, b, a + b); result = a + b; break; case 2: printf("%5.2f - %5.2f = %5.2f\n", a, b, a - b); result = a - b; break; case 3: printf("%5.2f * %5.2f = %5.2f\n", a, b, a * b); result = a * b; break; case 4: printf("%5.2f / %5.2f = %5.2f\n", a, b, a / b); result = a / b; break; case 5: result = a; for (float i = 0; i < b-1; i++) result *= a; printf("%5.2f ^ %5.2f = %5.2f\n", a, b, result); break; default: printf("Operaci���³n Desconocida\n"); break; } // Ask for go out printf("���¿Desea salir? [0:No, 1:Si]"); scanf("%d", &opcion); // Check the answer if (opcion == 1) salir = 1; else { salir = 0; printf("���¿Quieres conservar el resultado? [0:No, 1:Resultado es A, 2: Resultado es B]"); scanf("%d", &opcion); if (opcion == 1) lastresult = 1; else if (opcion == 2) lastresult = 2; else lastresult = 0; } // New Line printf("\n"); } // Exit of the program return 0; }
Initial URL
Initial Description
New Operation
Initial Title
Calculator V 2.1
Initial Tags
Initial Language
C