большая часть кода не показывает только приветственное сообщение и "вводить пин-код"? - PullRequest
0 голосов
/ 21 октября 2019

Назначение:

  1. Если вы введете неправильное количество цифр (3 или 5-значный номер пин-кода), должно появиться сообщение «Вы ввели неверный номер пин-кода !! ... вы должны ввестичетырехзначный пин-код. ”
  2. Показывая сообщение, которое отображалось ранее, программа должна позволить вам повторно ввести правильное количество цифр.
  3. Количество попыток должно быть три раза.
  4. Когда вы ввели правильное количество цифр, должно появиться сообщение «Ваш пин-код принят !!»
  5. Каждый раз, когда вы вводите любое количество цифр, оно должно отображаться в звездочке.

Код:

#include <conio.h>

#include <iostream>
//#include <cstdlib.h>
#include <cmath>

using namespace std;

int main() {
  string pass = "";
  int attempts = 3;

  cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;
  cout << "< Welcome to The Bank     >" << endl;
  cout << "<                         >" << endl;
  cout << "< Please Enter Pin Below  >" << endl;
  cout << " ^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;

  cout << "\nEnter Pin Number: " << endl;
  cin >> pass;

  // attempts= getch();
  while (attempts <= 3) {
    cout << "*";
    getch();
    attempts++;  // take this out and it display to infinity
                 // }

    if (pass == "1718") {
      cout << " lOGIN  IN..." << endl << endl;
      attempts = -1;
    }

    else {
      cout << "\nWRONT PIN-TRY AGAIN: " << endl << endl;
      attempts--;
      cout << " REMAINING ATTEMPTS: " << attempts << endl << endl;
    }

    if (attempts == 0) {
      cout << "Exceed the Pin attempts. Try Later. " << endl << endl;
    }

    if (attempts == -1) {
      cout << "********************************" << endl;
      cout << "*  Welcome to Magali's Bank    *\n";
      cout << "*  Select Option:              *\n";
      cout << "*    1. Check Balance          *\n";
      cout << "*    2. Withdraw               *\n";
      cout << "*    3. Deposit                *\n";
      cout << "*    4. Exit                   *\n";
      cout << "********************************\n";

      int balance = 500;
      float withdraw;
      float deposit;
      int user;

      cout << "Enter Number: ";
      cin >> user;

      while (user != 4) {
        switch (user) {
          case 1:
            cout << " Your balance is: " << balance << endl;
            break;

          case 2:
            cout << "Enter the amount you want withdraw: ";
            cin >> withdraw;
            balance = balance - withdraw;
            break;

          case 3:
            cout << "Enter the amount you want to deposit: ";
            cin >> deposit;
            balance = balance + deposit;
            break;

          default:
            cout << " Need to type 1 for Balance, 2 to Withdraw, 3 to Deposit "
                    "and 4 to Exit. ";
        }
        cout << "Enter Number: ";
        cin >> user;
      }
      cout << "\nTHANKS FOR USING THE SYSTEM!\n";
    }
  }
  return 0;
}

1 Ответ

0 голосов
/ 21 октября 2019

Ваш код имеет много недостатков, но, как вы и просили. Я только отлаживаю только часть его, где вам нужно принять ввод и отобразить ошибку.

string pass="";
int attempts=3;
const string pin = "1718";
//DO whatever you want 
//while loop to take input

while (attempts >0)
     {
         cout << "\nEnter Pin Number: " << endl;
         cin >> pass;
         for(auto i : pass)
            cout<<"*";
         if(pass == pin){
            attempts = 3;
            cout<<"Your Pin has been accepted.\n";
            break;}
        else{
        cout <<"\nWRONT PIN-TRY AGAIN: " << endl << endl;
       attempts--;
       cout << " REMAINING ATTEMPTS: " << attempts << endl << endl;
        }
    }

if (attempts == 0)
 {
 cout << "Exceed the Pin attempts. Try Later. "<< endl << endl;
 cout<<"Your account has been locked for a day .\n";
 exit(0);
 }

Прокомментируйте, если вы не поняли какую-либо часть.

...