## Posted By

OdnetninI on 09/08/12

# Calculator V 2.1

/ Published in: C

New Operation

`// Includes of the System#include <stdio.h>#include <inttypes.h> // Float variables of numbersfloat a = 0;float b = 0; // Float variable of resultfloat result = 0; // Check Variableuint8_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;}`