Advertisement
jzh4n

Untitled

May 17th, 2016
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #define FLUSH while(getchar() != '\n')
  6.  
  7. void programUtama() {
  8.     cout << "Program Utama\n\n";
  9.    
  10.     /*
  11.         TULIS PROGRAM UTAMA ANDA DI SINI
  12.     */
  13. }
  14.  
  15. int main() {
  16.     char *username = "123",
  17.         *password = "123",
  18.         input_username[100], input_password[100];
  19.        
  20.     int coba = 0;
  21.        
  22.     do {
  23.         cout << "Masukkan username: ";
  24.         cin >> input_username;
  25.        
  26.         FLUSH; // FLUSH BUFFER
  27.        
  28.         cout << "Masukkan password: ";
  29.         cin >> input_password;
  30.        
  31.         FLUSH; // FLUSH BUFFER
  32.        
  33.         if(strcmp(input_username, username) == 0 && strcmp(input_password, password) == 0) {
  34.             cout << "Login Berhasil\n\n";
  35.            
  36.             programUtama(); // <<-- JALANKAN PROGRAM UTAMA JIKA LOGIN BERHASIL
  37.            
  38.             return 0; // <<-- KELUAR DARI LOOPING DAN PROGRAM
  39.         }
  40.        
  41.         cout << "\n====================================\n";
  42.         cout << "Maaf USERNAME & PASSWORD ANDA Salah!\n";
  43.         cout << "====================================\n\n";
  44.  
  45.         coba += 1;
  46.     } while(coba < 3); // ULANGI MEMASUKKAN USERNAME DAN PASSWORD SAMPAI 3X JIKA TERJADI KESALAHAN
  47.    
  48.     cout << "Anda Telah 3x Memasukan ID & PASSWORD Yang Salah\n";
  49.     cout << "Mohon Maaf kesempatan Anda hanya 3x ";
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement