【问题标题】:how can I print a message in if statement? [closed]如何在 if 语句中打印消息? [关闭]
【发布时间】:2021-04-29 17:50:58
【问题描述】:
#include <iostream>
#include<string>
using namespace std;
int main() {
    string username, password, option, admin, client,type;
    cout << "enter the username" << endl;
    cin >> username;
    cout << "enter the password" << endl;
    cin >> password;
    cout << "are you admin or client?" << endl;
    cin >> option;
    if (option == admin) {
        cout << "Add a New Account." << endl;
        cout << "Modify An Account." << endl;
        cout << "Close An Account." << endl;
        cout << "List All Accounts." << endl;
    }
    else if (option == client) {
        cout << "Balance Enquiry" << endl;
        cout << "Withdraw Amount." << endl;
        cout << "Deposit Amount." << endl;
        cout << "Transfer from his account to another account." << endl;
    }
    cout << "Register as admin/client?" << endl;
    cin >> type;
    cout << "log out" << endl;

    return 0;
}

这 2 条消息你是管理员还是客户? && 注册为管理员/客户?在 if 语句中不输入就出现在彼此的后面

【问题讨论】:

  • 我认为您的意思是 if ( option == "admin" )else if 类似
  • 您有名为 adminclient 的字符串,但它们是空的

标签: c++ if-statement project message cout


【解决方案1】:

如果您将两个 if 语句检查更改为如下所示:

    if (option == "admin") {
        ...
    } else if (option == "client") {
        ...
    }

它可能会更好,因为目前它正在检查空字符串。

【讨论】:

    猜你喜欢
    • 2021-06-23
    • 1970-01-01
    • 2023-01-11
    • 2013-11-05
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多