Advertisement
xXG4briel

user//password

Apr 4th, 2020
1,665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <string.h> //para usar o strcmp()
  4. using namespace std;
  5.  
  6. int main(){
  7.     char user[30],password[7];   // variaveis
  8.     int retornoU=-10,retornoP=10; //  user: gabriel | password : 1234
  9.    
  10.     /*
  11.     0: igual
  12.     <0 str 1 menor que string 2
  13.     >0 str 1 maior que string 2
  14.     */
  15.    
  16.    
  17.     while(retornoU!=retornoP){
  18.         cout <<"user: ";
  19.         cin >>user;
  20.         retornoU=strcmp(user,"gabriel"); //verifica se as strings sao iguais e retorna 0 se for igual
  21.         system("cls"); // limpeza
  22.         if(retornoU==0){ // se o usuario digitado pelo usuario for igual ao salvo na  maquina
  23.             while(retornoP!=0){
  24.                 cout<<"user: " << user <<endl;
  25.                 cout <<"password: ";
  26.                 cin >>password;
  27.                 retornoP=strcmp(password,"123456"); //verifica se as strings sao iguais e retorna 0 se for igual
  28.                 system("cls"); //limpeza caso seja errado
  29.             }
  30.         }  
  31.     }
  32.     cout<< "Acesso permitido!\nBem vindo Gabriel\n";
  33.     system("pause");
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement