Yes, you're got the hang of if now. Just a comment though. There's no need for the second if in the if statement
if the result of the first if fails - is false - then the number must be outside the range ie is not between 1 and 100 so the second if is not needed in this case as it is always true. So this could be writtenCode:if (num1 >= 1 && num1 <= 100) cout << "\nYes " << num1 << " is between 1 & 100.\n" << endl; else if (num1 < 1 || num1 > 100) cout << "\nNo " << num1 << " is not between 1 & 100.\n" << endl;
The same with the num2 if test. Again the second if test is not needed. Although in this case the inverse logic of not 3 16 or 45 isCode:if (num1 >= 1 && num1 <= 100) cout << "\nYes " << num1 << " is between 1 & 100.\n" << endl; else cout << "\nNo " << num1 << " is not between 1 & 100.\n" << endl;
If you want to invert an if condition, then reverse each conditon (eg = to !=, > to <= etc) and change || to && and && to ||. For info, this is known as De Morgan's law.Code:if (num2 != 3 && num2 != 16 && num2 != 45)


Reply With Quote
Bookmarks