Hi, this is my first post here so if I make some mistake feel free to let me know. I'm in the process of working through a beginners C++ book ("I've had one class in high school and one in college so far, both C++ so I know a little more than I should for where I'm at in the book) and it gave me a program and told me to modify the program so if the user inputs wrong data it will shut the program down right then. I used a simple if statement for this. I will attach my code for the program. I've tested it a few times, seems to work fine. But I wanna know if there is some issue with how I did it that I'm not seeing
"I've tested it a few times, seems to work fine. But I wanna know if there is some issue with how I did it that I'm not seeing" You said it works fine so why would there be an issue?
choice cant be less than one AND greater than three, that means it is two different numbers, try this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
if (choice < 1){
cout << endl << "ERROR: Invalid data" << endl; // you didn't put an endl anywhere between
// cin choice and the ERROR, thus they would be on the same line, AND you didnt put an endl
// between line 28 and 29
return 0;
}
if (choice > 3){
cout << endl << "ERROR: Invalid data" << endl;
return 0;
}
@logart:
|| is the OR (inclusive OR) operator (the AND operator is &&). The OP's code is right. There is no need to repeat the same code with 2 seperate if statements.