C++ Membuat Program Input ID dan PASSWORD


Setelah sekitar 3 jam saya mencoba membuat program untuk menginputkan ID dan PASSWORD user, dan akhirnya saya berhasil membuat program tersebut dengan menggunakan fungsi perintah do while, karena program yang saya buat akan melakukan perulangan sebanyak 3x jika ID dan PASSWORD salah, dan setelah lebih dari 3x maka program akan berhenti. ohh iya...mohon maaf karena sementara saya hanya berhasil membuat input dengan angka, mungkin contoh program yang inputnya menggunakan huruf akan saya posting di lain waktu... inilah contoh output program saya

Output jika inputan ID dan PASSWORD benar !



Output jika ID& PASSWORD salah sebanyak 3x berturut turut

inilah kode program nya...

#include <iostream.h>
#include <conio.h>

main (void) {
    int username, password;
   int i;
cout << "------------------------------------------\n";
cout << "Selamat Datang Di Form Login Bosen Gaptek \n";
cout << "------------------------------------------\n\n";
  int user = 12345;
  int pass = 12345;
  i = 1;
   do {
       cout << "Username : "; cin >> username;
      cout << "Password : "; cin >> password;

       if (username = user && password == pass) {
         cout << "\n--------------------\n";
          cout << "Anda Berhasil Login" << endl;
         cout << "--------------------\n\n";
      } else {
          cout << "\n------------------------\n";
          cout << "Maaf ID & PASSWORD Salah!" << endl;
         cout << "-------------------------\n\n";
         i = i +1;
      }
   }
   while (i <= 3);

   cout << "Anda Telah 3x Memasukan ID & PASSWORD Yang Salah\n";
   cout << "Mohon Maaf Akun Anda Kami Blockir, Terima Kasih..";

   getch();
   }  

9komentar:

  1. #include
    #include
    #include

    main ()
    {

    char user[50], pass[20];
    int i;
    printf( "------------------------------------------\n");
    printf( "Selamat Datang Di Form Login Bosen Gaptek \n");
    printf( "------------------------------------------\n\n");
    i = 1;
    do {
    printf( "Username : ");gets(user);
    fflush(stdin);
    printf( "Password : ");gets(pass);

    if ((strcmp(user,"cantik")==0) && (strcmp(pass,"bdg120496")==0))
    {
    printf ( "\n--------------------\n");
    printf ( "Anda Berhasil Login \n" );
    printf ( "--------------------\n\n");
    printf ( " Selamat datang %s ditempat bahagia \n",user);
    break;

    }
    else {
    printf( "\n------------------------\n");
    printf( "Maaf ID & PASSWORD Salah!" );
    printf( "-------------------------\n\n");
    i = i +1;
    }
    }
    while (i <= 3) ;
    printf( "Anda Telah 3x Memasukan ID & PASSWORD Yang Salah\n");
    printf( "Mohon Maaf Akun Anda Kami Blockir, Terima Kasih..");

    getch();
    }

    BalasHapus
  2. ini nih kalo mau selain angka hahaha, tolong dicoba trus yg akhirnya masih suka ngikut, gimana cara ngilanginya

    BalasHapus
  3. bagus ni tapi
    gmana cara membuat program yang ketika loginnya salah dia akan mengulang.
    namun ketikan loginnya benar di tidak mengulang,

    BalasHapus
  4. ka maryam ko programnya gak bisa di running ya ? ada yang salah kayanya itu,,

    BalasHapus
  5. Gan,, kalo misalkan 12345 diganti dengan huruf bisa gak???? misalkan diganti dengan nama kita bgitu.../ghiovoelker@gmail.com

    BalasHapus
    Balasan
    1. pake string user = "Nama Agan";
      string pass = "Password Agan";

      Hapus
  6. pengin buat game di c++ tapi gk tau caranya jdinya kyk gini nih wwkwkwkwkwkwk
    #include
    #include
    #include
    // created by Farhan Mufti Hilmy
    using namespace std;

    int main()
    {
    string name;
    int age;
    int yesno;
    int hasil;
    int hasil2;

    cout << " "<< "----------------" << endl;
    cout << " "<< " Game Ragenah " << endl;
    cout << " "<< "----------------" << endl << endl;
    cout << "press any key to get started!" << endl;
    getch();
    cout << endl;
    cout << "Welcome to Game Ragenah. What's your Nickname?" << endl << endl;
    cin >> name;
    cout << endl;
    cout << "Hello " << name << "! Anyway how old are you?" << endl << endl;
    cin >> age;
    cout << endl;
    if(age<=10){
    cout << "you're too younger. Can you solve my problem? [1 to say yes/2 to say no]" << endl<< endl;
    cin >> yesno;
    cout << endl;
    } else if(age>=50){
    cout << "you're too old. Can you solve my problem? [1 to say yes/2 to say no]" << endl << endl;
    cin >> yesno;
    cout << endl;
    } else if((age>10) && (age<50)){
    cout << "Got it. Can you solve my problem? [1 to say yes/2 to say no]" << endl << endl;
    cin >> yesno;
    cout << endl;
    }


    if(yesno==1){
    cout << "That'll be great. Ok, Solve this problem 2345 * 2!" << endl << endl;
    cin >> hasil;
    cout << endl;
    } else if(yesno==2){
    cout << "You must be joking, right?. Ok, Solve this problem 2345 * 2!" << endl << endl;
    cin >> hasil;
    cout << endl;
    }


    if(hasil==4690){
    cout << "Well done!. You're good at math, How about 98272638 * 3?" << endl << endl; // 294817914
    cin >> hasil2;
    cout << endl;
    if(hasil2==294817914){
    cout << "Oh surely, you used a calculator, isn't it?. But no problem, it's okay" << endl << endl;
    getch();
    cout << "Thanks for solved my problem, I'll give you a surprise" << endl << endl;
    getch();
    for(int i=1;i<=10;i++){
    for(int j=1;j<=10;j++){
    cout << j << " x " << i << " = " << j*i << " " << endl;
    }
    cout << endl;
    }
    cout << endl << endl;
    cout << "That's it. Hope you like it";
    getch();


    } else {
    cout << "Sorry you lose" << endl;
    cout << "_____ _____" << endl;
    cout << " |__| |_| " << endl;
    cout << " ___ " << endl;
    cout << " \ / " << endl;
    cout << "__ __" << endl;
    cout << " --__ __-- " << endl;
    cout << " --___-- " << endl;
    getch();
    }

    } else{
    cout << "Sorry, you lose" << endl;
    cout << "_____ _____" << endl;
    cout << " |__| |_| " << endl;
    cout << " ___ " << endl;
    cout << " \ / " << endl;
    cout << "__ __" << endl;
    cout << " --__ __-- " << endl;
    cout << " --___-- " << endl;
    getch();
    }

    getch();



    }

    BalasHapus
  7. Kak kalo dibikinnya pakek array,bisa gak? Mohon bantuannya kak buat projek kuliah🙏

    BalasHapus