gpt4 book ai didi

c++ - 大多数代码不只显示欢迎消息和 “enter pin”吗?

转载 作者:行者123 更新时间:2023-12-02 10:38:23 25 4
gpt4 key购买 nike

分配:

  • 输入错误的数字位数(3或5位数字的密码)时a
    消息应显示“您输入的密码不正确!!
    必须输入四位数的密码。”
  • 通过显示以前显示的消息,程序应
    允许您重新输入正确的数字位数。
  • 尝试次数应为3次。
  • 输入正确的数字后,将显示一条消息
    “您的密码已被接受!”
  • 每次输入任意数量的密码时,密码都必须以星号显示。

  • 码:
    #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;
    }

    最佳答案

    您的代码效率低下,但您却要求这样做。我只调试其中的一部分,您需要输入和显示错误。

    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);
    }

    如果您不了解任何部分,请注释掉。

    关于c++ - 大多数代码不只显示欢迎消息和 “enter pin”吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58477947/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com