Advertisement
BlueX

[C++]: Find Even Number

Aug 2nd, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.51 KB | None | 0 0
  1. /*
  2. =====================================
  3. >                                   <
  4. <          FIND EVEN NUMBER         >
  5. >             by BlueX              <
  6. <                                   >
  7. >         [iPs]TeaM (c) 2012        <
  8. <                                   >
  9. =====================================
  10. */
  11. #include <iostream>
  12. #include <string>
  13. #include <Windows.h>
  14.  
  15. using namespace std;
  16.  
  17. char isPrimaryNumber(char Input[]);
  18. char isNumeric(char Input[]);
  19.  
  20. void SendColoredText(string str, int color);
  21. int restart();
  22.  
  23. int main(){
  24.     char userInput[50];
  25.  
  26.     SendColoredText("\t ============[",14),SendColoredText(" BlueX Find Even Number ",15),SendColoredText("]============\n",14);
  27.     Sleep(1500);
  28.     SendColoredText("Insira um numero: ", 15);
  29.     cin.getline(userInput,50);
  30.     cout << endl;
  31.  
  32.     if(!isNumeric(userInput)){
  33.         SendColoredText("[",15),SendColoredText("ERRO",4);SendColoredText("]:",15),SendColoredText(" Insira apenas numeros!",15);
  34.         restart();
  35.     }
  36.     if(isPrimaryNumber(userInput)){
  37.         SendColoredText("[ ", 15),SendColoredText("PAR", 2),SendColoredText(" ] - numero: ", 15),SendColoredText(userInput, 15),cout << endl,restart();
  38.     }
  39.     else
  40.         SendColoredText("[ ", 15),SendColoredText("IMPAR", 4),SendColoredText(" ] - numero: ", 15),SendColoredText(userInput, 15),cout << endl,restart();
  41.  
  42.     //system("pause");
  43.     return 0;
  44.  
  45. }
  46.  
  47. char isNumeric(char Input[]){
  48.     for(int i = 0, j = strlen(Input); i < j; i++)
  49.     {
  50.         if(Input[i] > '9' || Input[i] < '0') return 0;
  51.     }
  52.     return 1;
  53. }
  54.  
  55. char isPrimaryNumber(char Input[]){
  56.     int pos;
  57.     pos = strlen(Input);
  58.     if(Input[pos-1] == '0' || Input[pos-1] == '2' || Input[pos-1] == '4' || Input[pos-1] == '6' || Input[pos-1] == '8')
  59.         return 1;
  60.     return 0;
  61. }
  62.  
  63. void SendColoredText(string str, int color){
  64.     HANDLE hConsole;
  65.  
  66.     hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  67.     SetConsoleTextAttribute(hConsole, color);
  68.     cout << str;
  69.     SetConsoleTextAttribute(hConsole, 15);
  70. }
  71.  
  72. int restart(){
  73.     char a[2];
  74.     int error = 0;
  75.     if(error == 0){
  76.         Sleep(2500);
  77.         system("CLS");
  78.     }
  79.     SendColoredText("Voce deseja restar o programa?\n",15);
  80.     SendColoredText("[N]",4),SendColoredText(" - Nao\n",15);
  81.     SendColoredText("[S]",2),SendColoredText(" - Sim\n",15);
  82.     SendColoredText("Opcao: ",15);
  83.     cin.getline(a,2);
  84.     if(a[0] == 'N' || a[0] == 'n') return 0;
  85.     else if(a[0] == 'S' || a[0] == 's'){
  86.         system("CLS");
  87.         main();
  88.     }
  89.     else {
  90.         SendColoredText("[",15),SendColoredText("ERRO",4);SendColoredText("]:",15),SendColoredText(" Insira apenas S ou N!",15);
  91.         a[0] = '\1';
  92.         restart();
  93.     }
  94.     return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement