Вопрос задан 03.11.2023 в 13:28. Предмет Информатика. Спрашивает Мирсанов Дима.

СРОЧНО. на с ++пожалуйста Напишем программу, которая имитирует процессввода пароля: если пароль

Введен верно, должнывыводиться сообщение "Successful login", если жепароль был введен неправильно, то должновыводиться сообщение "Wrong password". Если жепароль был введен неправильно 3 раза, то процессввода должен прерываться и должно выводитьсясообщение Access deniedначинаться программа должна с выводасообщения Enter correct password", после чегодолжно предлагаться ввести правильный парольпосле чего уже должны вводиться попытки вводаЭтото пароля​
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Вережак Саня.

#include <iostream>

int main()

{

       using namespace std;

       const string password = "123456";

       string attempted;

       cout << "Enter correct password" << endl;

       for (int i = 0; i < 3; i++)

       {

               cin >> attempted;

               if (attempted == password)

               {

                       cout << "Successful login" << endl;

                       return 0;

               }

               else

               {

                       cout << "Wrong password" << endl;

               }

       }

       cout << "Access denied" << endl;

       return 0;

}

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

To create a program that simulates the password entry process, you can use a combination of loops and conditional statements. Here's an example of how you can implement it in Python:

```python def password_program(): password = "password123" attempts = 0

while attempts < 3: user_input = input("Enter password: ")

if user_input == password: print("Successful login") break else: print("Wrong password") attempts += 1

if attempts == 3: print("Access denied")

password_program() ```

Let's break down the code:

1. We define the correct password as a string variable `password` (in this case, "password123"). 2. We initialize the variable `attempts` to keep track of the number of incorrect password attempts. 3. We use a `while` loop to repeatedly ask the user to enter the password until they get it right or reach the maximum number of attempts (3 in this case). 4. Inside the loop, we prompt the user to enter the password using the `input()` function and store their input in the `user_input` variable. 5. We compare the `user_input` with the `password` using an `if` statement. If they match, we print "Successful login" and exit the loop using the `break` statement. 6. If the passwords don't match, we print "Wrong password" and increment the `attempts` variable by 1. 7. After the loop, we check if the number of attempts is equal to 3. If so, we print "Access denied" because the user has exceeded the maximum number of attempts.

You can run this code in a Python environment to see how it works. Remember to replace "password123" with your desired password.

0 0

Похожие вопросы

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос