Last active
May 3, 2020 17:01
-
-
Save geektutor/437bab37ad95c8841251e966aa164dbe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
barnyard(head: 20, leg: 76); | |
} | |
barnyard({head, leg}) { | |
var goat = (leg / 2) - head; | |
var chicken = head - goat; | |
if (goat is int && | |
chicken is int && | |
!goat.isNegative && | |
!chicken.isNegative) { | |
print('There are $goat goats and $chicken chicken in my barnyard'); | |
} else { | |
print('Invalid entries. Try again'); | |
} | |
} | |
/* I used c + 3g = leg-head and c + g = head to get g = (leg/2) - head & c = head - g | |
* | |
* I intentionally allowed the user to enter more than int because I dont want the red error of the compiler and want to define my own error statement | |
* */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment