Advertisement
LightProgrammer000

Fatorial [Menu Interativo]

Nov 29th, 2018
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.74 KB | None | 0 0
  1. /// Bibliotecas
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #include <locale.h>
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. /// Funções
  9. char Menu(char r);
  10.  
  11. /// Programa
  12. int main ( int argc , char *argv[] )
  13. {
  14.     // Variável Estratégica
  15.     char r = 'A';
  16.  
  17.     for ( r != 'n'; r != 'n'; )
  18.     {
  19.         // Variáveis
  20.         int i, n, fat = 1, aux;
  21.  
  22.         // Sistemas
  23.         setlocale(LC_ALL, "");
  24.         system("cls & color F");
  25.  
  26.         // Apresentação
  27.         cout << " ========================== " << endl;
  28.         system("echo  - Usuario: %username%");
  29.         system("echo  - Computador: %computername%");
  30.         system("echo  - Hora: %time:~0,-3%");
  31.         system("echo  - Data: %date:/=-%");
  32.         cout << " ========================== " << endl;
  33.  
  34.         cout << "\n - Digite um Valor: ";
  35.         cin >> n;
  36.  
  37.         if ( (n < 0 || n > 13) )
  38.         {
  39.             system("cls");
  40.             cout << "\n\n";
  41.             cout << " - Somente Valores entre 1 e 12\n";
  42.             cout << " - Somente Valores entre 1 e 12\n";
  43.             cout << " - Somente Valores entre 1 e 12\n";
  44.             system("color C & timeout /t 5");
  45.             cout << "\n" <<endl;
  46.         }
  47.  
  48.         else
  49.         {
  50.             // Controle
  51.             aux = n;
  52.  
  53.             // Forma 1
  54.             cout << "\n - Forma de Cálculo 1" << endl;
  55.             for ( ; n > 0; n-- )
  56.             {
  57.                 if ( n == 1 )
  58.                 {
  59.                     cout << "\n - Resultado ["<< n <<"]:  " << (fat *= n) << endl;
  60.                     break;
  61.                 }
  62.  
  63.                 else
  64.                 {
  65.                     cout << " - [" << n <<"]: " << (fat *= n) << endl;
  66.                 }
  67.             }
  68.             cout << " ------------------------------------- \n" << endl;
  69.  
  70.  
  71.             // Controle
  72.             fat = 1;
  73.  
  74.             // Forma 2
  75.             cout << "\n - Forma de Cálculo 2" << endl;
  76.             for ( i = 1; i <= aux; i++ )
  77.             {
  78.                 if ( i == aux )
  79.                 {
  80.                     cout << "\n - Resultado ["<< i <<"]: " << (fat *= i) << endl;
  81.                     break;
  82.                 }
  83.  
  84.                 else
  85.                 {
  86.                     cout << " - [" << i <<"]: " << (fat *= i) << endl;
  87.                 }
  88.             }
  89.  
  90.             cout << " ------------------------------------- \n\n" << endl;
  91.             //system("pause");
  92.         }
  93.  
  94.         r = Menu(r);
  95.     }
  96.     return(0);
  97. }
  98.  
  99. ////////////////////// FUNÇÕES //////////////////////
  100.  
  101. char Menu(char r)
  102. {
  103.     cout << "\n - Deseja Continuar a Calcular ?" << endl;
  104.     cout << " - [s] Sim" << endl;
  105.     cout << " - [n] Não" << endl;
  106.     cout << " - Opc.: ";
  107.     r = getche();
  108.  
  109.     return(r);
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement