/ Published in: C
New Operation
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// 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 ) { } else if (lastresult == 1) { a = result; } else if (lastresult == 2) { b = result; } } /* Fuction PrintfOptions Printf the Options */ void PrintfOptions () { } /* 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 // Check if answer is correct if (opcion > 0 && opcion < 6) AskNumbers(); // Make the operation switch (opcion) { case 1: result = a + b; break; case 2: result = a - b; break; case 3: result = a * b; break; case 4: result = a / b; break; case 5: result = a; for (float i = 0; i < b-1; i++) result *= a; break; default: break; } // Ask for go out // 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]"); if (opcion == 1) lastresult = 1; else if (opcion == 2) lastresult = 2; else lastresult = 0; } // New Line } // Exit of the program return 0; }