-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();
}
Illyduss
  • 161
  • 1
  • 3
  • 11
  • 4
    Is this `if (account = "New" or "NEW" or "new"){` correct? I think not. – Ed Heal Jun 07 '15 at 17:08
  • What is wrong with it, I did that same thing for a few practice If checks and they all worked. Although they only checked to see if a int was higher than 100, like so: ( number < 100?) { – Illyduss Jun 07 '15 at 17:10
  • 1
    Trying to compare an `int` with a string will not work extremely well. And either not compiling with warnings, not paying attention to warnings, or not using a compiler that gives those warnings. – chris Jun 07 '15 at 17:11
  • @chris actually he is trying to assign a string to an int: `account = "NEW"` is an assignment not a comparison (which would be `==`). – 463035818_is_not_an_ai Jun 07 '15 at 18:57
  • @tobi303, The code says assignment, but the intent was probably to compare them. – chris Jun 07 '15 at 18:59

1 Answers1

2

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.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
  • That works! Thanks, I thought I actually figured it out after my post by changing int to char, but then I ran into other problems. Thanks, I now know a new trick! – Illyduss Jun 07 '15 at 17:21
  • You should also convert your variable to all lower case or all upper case to reduce the number of comparisons. For example, you are missing the cases "nEw", and "neW" to name a couple. – Thomas Matthews Jun 07 '15 at 18:22
  • @Thomas Matthews There was written already about this in my post. – Vlad from Moscow Jun 07 '15 at 18:38