Cooler_

cacl exemplo

Jul 14th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. // exemplo de calc que fiz pro meu brothe guinha
  2. #include <stdio.h>
  3.  
  4. char  line[100],operator;
  5. int   result,value;
  6.  
  7.  
  8. char opcao_menu()
  9. {
  10.     int i;
  11.     char *banner[] = {
  12.         "Operator Calc",
  13.         "coded by Cooler_  ",
  14.         "put with example",
  15.         "operators:+,-,*,/ ",
  16.         "(s)para Sair",
  17.         "-> ",
  18.     };
  19.     for(i=0; i<=5; i++)
  20.         printf(" %s \n",banner[i]);
  21. }
  22.    
  23. int main()
  24. {
  25.     opcao_menu();
  26.     result = 0;
  27.  
  28.     while (1)
  29.     {
  30.         printf("Resultado: %d\n", result );
  31.         printf("Digite Operador e o numero : ");
  32.  
  33.         fgets(line, sizeof(line), stdin);
  34.         sscanf(line, "%c %d", &operator, &value);
  35.  
  36.         if ((operator == 's') || (operator == 'S'))
  37.             break;
  38.         if (operator == '+')
  39.             result += value;
  40.         if (operator == '/')
  41.             result /= value;
  42.         if (operator == '-')
  43.             result -= value;
  44.         if (operator == '*')
  45.             result *= value;
  46.     }
  47.     return(0);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment