/ Published in: C
Two new fuctions and two bugs repaired
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Includes of the System #include <stdio.h> #include <inttypes.h> #include <math.h> // Float variables of numbers float a = 0; float b = 0; // Float variable of result float result = 0; // Check Variable uint8_t lastresult = 0; uint8_t error = 0; // Define PI #define PI 3.14159265 #define RADIAN (PI/180) #define GRADOS (180/PI) /* 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(); else if (opcion >= 6 && opcion < 13) { if (lastresult == 0 ) { } else { a = result; } } // 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; case 6: break; case 7: break; case 8: break; case 9: break; case 10: break; case 11: result = a * RADIAN; break; case 12: result = a * GRADOS; break; case 99: salir = 1; error = 1; return 0; break; default: error = 1; break; } // Ask for go out // Check the answer if (opcion == 1) salir = 1; else { salir = 0; if (error == 0) { if (opcion == 1) lastresult = 1; else if (opcion == 2) lastresult = 2; else lastresult = 0; } error = 0; } // New Line } // Exit of the program return 0; }