微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 if 语句中打印消息?

如何解决如何在 if 语句中打印消息?

#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 语句检查更改为如下所示:

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。