-1

Maybe my code is sloppy, but for some reason it just passes through all the nested If checks without pausing to check for an answer beyond the first one. Also the first If check goes on to the nested If for True no matter what even if I give it a False answer. I'm rather new to C++ so is there something I'm missing?

#include <iostream>
#include <string>

using namespace std;

int main()
{
    cout<<" \n";
    cout<<"UUU   UUU   RRRRRRR   TTTTTTTTT  HHH  HHH\n";
    cout<<"UUU   UUU   RRR  RRR     TTT     HHH  HHH\n";
    cout<<"UUU   UUU   RRRRRRR      TTT     HHHHHHHH\n";
    cout<<"UUU   UUU   RRR  RRR     TTT     HHH  HHH\n";
    cout<<" UUUUUUU    RRR   RRR    TTT     HHH  HHH\n";
    cout<<" \n";
    cout<<"           Created by: Illyduss\n";
    cout<<"                     2015\n";
    cout<<" \n";
    cout<<" \n";
    cout<<" \n";
    int account;
    cout<<"Do you already have an account? \n";
    cout<<"Type 'New' to create an account or enter your account name.\n";
    cout<<"Account Name: ";
    cin>> account;
    cin.ignore();
    if (account = "New" or "NEW" or "new"){
        string surname;
        cout<<" \n";
        cout<<"Account names serve as the Surname or Last name for\n";
        cout<<"all characters linked to said account. This is beca\n";
        cout<<"use of our unique gene pool system. Which will be c\n";
        cout<<"overed more in depth later on, but for now just thi\n";
        cout<<"nk of it like this, an account is a family tree for\n";
        cout<<"all of your characters.\n";
        cout<<" \n";
        cout<<"Please enter your desired Surname Name: ";
        cin>> surname;
        cin.ignore();
        if (surname.length() > 2){
            cout<<" \n";
            cout<<"You have chosen, '" << surname << "' as your surname, correct? ";
        }
        else {
            cout<<"That is too short, please choose another surname: ";
        }
    }
    else {
        cout<< "Welcome back, '" << account << "'!\n";
        cout<<"Please enter your password: ";
    }
    cin.get();
}
4

1 回答 1

2

首先,您尝试使用类型的对象int来输入字符串,然后您尝试使用不正确的条件和赋值运算符将此对象与字符串文字进行比较

if (account = "New" or "NEW" or "new"){
            ^^

您应该定义account为具有类型std::string,在这种情况下,条件可能看起来像

if (account == "New" or account == "NEW" or account == "new"){

但无论如何,最好account使用一些中间对象转换为大写。在这种情况下,条件看起来会更简单。

于 2015-06-07T17:14:10.263 回答