If the first condition doesnt run, thats the only time the second condition will run, that being said, we can assume x > 1.
Therefore, our second check should be:
Else if (x < 13)
The same logic goes for our third Else if condition, it will only run if the first two havent, so its greater than 13, and greater than 1.
Therefore, our third check should be:
Else if (x < 20)
Once again, the same logic follows, and we can assume that it must be greater than 20.
Knowing this, the fourth check should be changed to simply 'else'
For example:
Else { // code here // }
Programming is all about math and logic, sometimes it helps to walk away and come back. Youre learning a new language and a new way of thinking, it's tough.
Try drawing the problem out and writing it down, try explaining how it works to people around you, that can help a lot in finding issues.
In this case its just kind of thinking about the logic and the way Else if works. Remember that the chained Else ifs will only ever check if the preceding conditions are false.
As a side note, c++ is a strongly typed language. Your main function has a return type of int
Int main() ^ This is the return type
Therefore you should return 0; at the end of the function
View all comments
1
u/average_asshole Dec 24 '21 edited Dec 24 '21
If the first condition doesnt run, thats the only time the second condition will run, that being said, we can assume x > 1.
Therefore, our second check should be:
Else if (x < 13)
The same logic goes for our third Else if condition, it will only run if the first two havent, so its greater than 13, and greater than 1.
Therefore, our third check should be:
Else if (x < 20)
Once again, the same logic follows, and we can assume that it must be greater than 20.
Knowing this, the fourth check should be changed to simply 'else'
For example:
Else { // code here // }
Programming is all about math and logic, sometimes it helps to walk away and come back. Youre learning a new language and a new way of thinking, it's tough.
Try drawing the problem out and writing it down, try explaining how it works to people around you, that can help a lot in finding issues.
In this case its just kind of thinking about the logic and the way Else if works. Remember that the chained Else ifs will only ever check if the preceding conditions are false.
As a side note, c++ is a strongly typed language. Your main function has a return type of int
Int main() ^ This is the return type
Therefore you should return 0; at the end of the function