Nesting if checks with C++

79 views Asked by At

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

There are 1 answers

3
Vlad from Moscow On BEST ANSWER

First of all you are trying to use an object of type int that to enter a string and then you are trying to compare this object with string literals using an incorrect condition and the assignment operator

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

You should define account as having type std::string and in this case the condition can look like

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

but in any case it would be better to convert account using some intermediate object to upper case. In this case the condition will look simpler.