Help with some basic coding
Also, when I run the code and use the number 20, it still works for 20, is there any way to make it only work for 19 and below? I can simply change the test to under 21....this is just a test program I'm creating, just for the principle and logic I'm trying to figure it out. I don't understand the || operator, an overload? Google is not my friend today I guess.
Edit: Figured this one out just changed the numbers a little bit lol it's been a long day.
This
FavNumber < 0 || FavNumber > 20
Translates to: (if favNumber is lower than 0) OR (if favNumber is higher than 20) go inside the loop. If you don't want the 20 to be included you can easily say (if favNumber is equal or higher than 20) which is FavNumber >= 20.
Now if the user enters a string the compiler is going to convert it to an integer which is not possible because an integer has 4bytes and inside a string every character is one byte. So you will end up with garbage values. Pay attention that there is a possibility that a string might give a garbage value inside 0 to 20 and your program will think it is correct but this possibility is very unlikely to happen.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now