Do While Help

I am trying to make a simple script. The problem I am running into is where I am trying to make a code to where if a person doesn't type in an appropiate letter then the code will say "Please select an appropriate number." If the person was to select a good number (1 to 6), an if statement would evaluate which number was chosen then output the text. However, no matter what number I put in, I always get 'Please select an appropriate number". How do I fix this?



#include <iostream>
using namespace std;

void username(){
cout << "Please enter your username > " << flush;

string name;
cin >> name;
}

void classes(){

const int number1 = 1;
const int number2 = 2;
const int number3 = 3;
const int number4 = 4;
const int number5 = 5;
const int number6 = 6;

cout << "Choose a class from below:" << endl;
cout << "===============================" << endl;
string classes[2][3]{
{"1. Warrior", "2. Hunter", "3. Mage"},
{"4. Warlock", "5. Paladin", "6. Rogue"}
};

for(int i = 0; i < 2; i++){
for(int j = 0; j < 3; j++){
cout << classes[i][j] << " " << flush;
}
cout << endl;
}

cout << "===============================" << endl;

int pick;

do{
cout << "Please select a class!" << endl;
cin >> pick;

if(pick != number1) || (pick != number2) || (pick != number3) || (pick != number4) || (pick != number5) || (pick != number6){
cout << "Please select an appropiate number!" << endl;
}
}while(pick != number1) || (pick != number2) || (pick != number3) || (pick != number4) || (pick != number5) || (pick != number6);

if(pick == 1){
cout << "You selected Warrior!" << endl;
}
if(pick == 2){
cout << "You selected Hunter!" << endl;
}
if(pick == 3){
cout << "You selected Mage!" << endl;
}
if(pick == 4){
cout << "You selected Warlock!" << endl;
}
if(pick == 5){
cout << "You selected Paladin!" << endl;
}
if(pick == 6){
cout << "You selected Rogue!" << endl;
}

}

int main(){
username();
classes();

return 0;
}

if(pick != number1) || (pick != number2) || (pick != number3) || (pick != number4) || (pick != number5) || (pick != number6){
Quite, quite wrong :(

if((pick != 1) && (pick != 2 ) && (pick != 3 ) && (pick != 4 ) && (pick != 5 ) && (pick != 6 )) {
Understanding the difference between || and && is very important. Don't go on until you do.
Last edited on
Topic archived. No new replies allowed.