Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 540 541 [542] 543 544 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 882597 times)

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8115 on: October 07, 2015, 07:34:22 pm »

I'm saying get two variables, hours and minutes, and store/check them separately.  So, if I understand you correctly, yes.

But why would you make two IF's? If one of the ifs for error are triggered then why check the rest?

Doing If (Hours <24) and if (minutes <.59) would make two seprate checks and that could continue the program despite its answer being flawed.
Code it as:
Code: [Select]
if (hours > 24 || minutes >59) {
throw error
}

do other stuff
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8116 on: October 07, 2015, 07:43:12 pm »

I'm saying get two variables, hours and minutes, and store/check them separately.  So, if I understand you correctly, yes.

But why would you make two IF's? If one of the ifs for error are triggered then why check the rest?

Doing If (Hours <24) and if (minutes <.59) would make two seprate checks and that could continue the program despite its answer being flawed.
Code it as:
Code: [Select]
if (hours > 24 || minutes >59) {
throw error
}

do other stuff

Spoiler: Code (click to show/hide)

Like so? Doesn't seem to compile for me..
Logged

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8117 on: October 07, 2015, 07:43:30 pm »

Again, typing 19.-33 won't trigger the first error because 19.-33 is not an actual number. When you store input as a number the variable can only take values that are actual numbers and so minuteRemainder will never be less than 0. Also because of how cin works when you type 19.-33 it treats it as "19." and "-33" because it stops when it encounters the minus sign when it is taking the first number.
Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8118 on: October 07, 2015, 07:44:36 pm »

I'm saying get two variables, hours and minutes, and store/check them separately.  So, if I understand you correctly, yes.

But why would you make two IF's? If one of the ifs for error are triggered then why check the rest?

Doing If (Hours <24) and if (minutes <.59) would make two seprate checks and that could continue the program despite its answer being flawed.
Code it as:
Code: [Select]
if (hours > 24 || minutes >59) {
throw error
}

do other stuff
Thanks.

I misrepresented my suggestion.  You shouldn't change the singular if statement which you have checking the validity.
But you should definitely take minutes and hours in as separate variables, because as others have said, the .-33 is not reaching your code properly.
It should stop messing up.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8119 on: October 07, 2015, 07:45:21 pm »

Also, that code won't compile because you forgot a curly brace after the error check. || means "or", in case that wasn't mentioned.
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8120 on: October 07, 2015, 08:02:37 pm »

Also, that code won't compile because you forgot a curly brace after the error check. || means "or", in case that wasn't mentioned.

Found that after I posted  :-[

Again, typing 19.-33 won't trigger the first error because 19.-33 is not an actual number. When you store input as a number the variable can only take values that are actual numbers and so minuteRemainder will never be less than 0. Also because of how cin works when you type 19.-33 it treats it as "19." and "-33" because it stops when it encounters the minus sign when it is taking the first number.

I'm saying get two variables, hours and minutes, and store/check them separately.  So, if I understand you correctly, yes.

But why would you make two IF's? If one of the ifs for error are triggered then why check the rest?

Doing If (Hours <24) and if (minutes <.59) would make two seprate checks and that could continue the program despite its answer being flawed.
Code it as:
Code: [Select]
if (hours > 24 || minutes >59) {
throw error
}

do other stuff
Thanks.

I misrepresented my suggestion.  You shouldn't change the singular if statement which you have checking the validity.
But you should definitely take minutes and hours in as separate variables, because as others have said, the .-33 is not reaching your code properly.
It should stop messing up.

I don't think I understand. Can you re-word this a bit?

What I think i'm getting is that I should: Keep my startime check and after that bit of code ask for minutes. Once I get minutes I should check it to make sure its fine?

I use minute *Garbled mind blown*

Okay. I'm doing this now.

else if (minuiteRemainder < 0.00 || minutes < 0){

How would that stop me from inputing 19.333 as a time?
Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8121 on: October 07, 2015, 08:04:56 pm »

You need to get two things from the user (number of hours and also number of minutes), instead of one compound thing (number of hours with number of minutes stuck on the end).
Other than that, you should be good, as long as you fix the actual variables and the numbers.
« Last Edit: October 07, 2015, 08:06:41 pm by TheBiggerFish »
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8122 on: October 07, 2015, 08:46:23 pm »

What sorts of user input are you dealing with, here? Because if you really want to idiot-proof this, you'll probably want to do something like storing the input as a string, then attempting to parse every format you can imagine down to a correct sequence of numbers, and generate an error message for the ones you don't predict or which are too ambiguous. That's probably more than you really want.

Realistically, you should probably be getting two separate inputs for each of minutes and hours, because despite time being measured numerically most common representations aren't numbers as far as the computer is concerned. For example, ':' isn't a valid character in a numeral, and the time 6.30 is very much not the same as the decimal number 6.30. So you should expect that user input won't be in the form of a number.

EDIT: So the user would see something like "Please enter the hour" followed by "Please enter the minute" after they entered the hour.
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8123 on: October 07, 2015, 08:47:31 pm »

What sorts of user input are you dealing with, here? Because if you really want to idiot-proof this, you'll probably want to do something like storing the input as a string, then attempting to parse every format you can imagine down to a correct sequence of numbers, and generate an error message for the ones you don't predict or which are too ambiguous. That's probably more than you really want.

Realistically, you should probably be getting two separate inputs for each of minutes and hours, because despite time being measured numerically most common representations aren't numbers as far as the computer is concerned. For example, ':' isn't a valid character in a numeral, and the time 6.30 is very much not the same as the decimal number 6.30. So you should expect that user input won't be in the form of a number.

EDIT: So the user would see something like "Please enter the hour" followed by "Please enter the minute" after they entered the hour.
Yeah.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

EnigmaticHat

  • Bay Watcher
  • I vibrate, I die, I vibrate again
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8124 on: October 07, 2015, 09:47:30 pm »

Arch Linux
This sounds fake.

Like someone was making a computer wizard joke.
Logged
"T-take this non-euclidean geometry, h-humanity-baka. I m-made it, but not because I l-li-l-like you or anything! I just felt s-sorry for you, b-baka."
You misspelled seance.  Are possessing Draignean?  Are you actually a ghost in the shell? You have to tell us if you are, that's the rule

Avis-Mergulus

  • Bay Watcher
  • This adorable animal can't work.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8125 on: October 07, 2015, 09:54:25 pm »

Arch Linux
This sounds fake.

Like someone was making a computer wizard joke.
Little did EnigmaticHat know... It was not a computer wizard joke, but instead a horrifying computer wizard reality.
Logged
“See this Payam!” cried the gods, “He deceives us! He cruelly abuses our lustful hearts!”

EnigmaticHat

  • Bay Watcher
  • I vibrate, I die, I vibrate again
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8126 on: October 07, 2015, 10:07:34 pm »

Sorry.
Logged
"T-take this non-euclidean geometry, h-humanity-baka. I m-made it, but not because I l-li-l-like you or anything! I just felt s-sorry for you, b-baka."
You misspelled seance.  Are possessing Draignean?  Are you actually a ghost in the shell? You have to tell us if you are, that's the rule

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #8127 on: October 08, 2015, 11:37:17 am »

I seem to have tangled myself up in a hell of inheritance and static data classes.

Say I have a class called Animal, which defines things like a position for the animal. Then I have a class called StaticAnimal, which defines data that is common to all animals of a specific species. It doesn't make sense to copy this data every time I make an animal of that type, so every Animal of a specific type just contains a const pointer to a single instance of StaticAnimal.

But then I add in some child classes for Animal, like Dog. It contains some dynamic dog-specific information and overridden functions, but now I need some static data. Out comes StaticDog, which inherits from StaticAnimal. It sounds pretty logical, but then I start seeing flaws. Every object of a type that derives from Animal has a pointer to both its own static type and a StaticAnimal object, which isn't so much a problem as it is inelegant. I realize later that I need to change the static data pointed to by an Animal-derived object sometimes, which means every child class needs its own individual setStaticData function. Problems just seem to keep piling up.


Anybody here have a policy they usually use for storing separate static data like this? My method here was essentially developed in a vacuum, I've never seen other people's methods before.
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

EnigmaticHat

  • Bay Watcher
  • I vibrate, I die, I vibrate again
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8128 on: October 08, 2015, 01:25:24 pm »

Can the data for each species be expressed as an array?  If the answer is yes, use a dictionary of string keys and array values.  Make it part of a class that has functions that take a key and retrieve a given value from the array.

Alternately, make a separate dictionary for each property, and give them all the same keys for each species.  So something like numberOfLegsDict, numberOfEyesDict, each of which accepts the values of "dog" and "spider".
Logged
"T-take this non-euclidean geometry, h-humanity-baka. I m-made it, but not because I l-li-l-like you or anything! I just felt s-sorry for you, b-baka."
You misspelled seance.  Are possessing Draignean?  Are you actually a ghost in the shell? You have to tell us if you are, that's the rule

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #8129 on: October 08, 2015, 01:53:02 pm »

Can the data for each species be expressed as an array?  If the answer is yes, use a dictionary of string keys and array values.  Make it part of a class that has functions that take a key and retrieve a given value from the array.

Alternately, make a separate dictionary for each property, and give them all the same keys for each species.  So something like numberOfLegsDict, numberOfEyesDict, each of which accepts the values of "dog" and "spider".
Hmm, I didn't think of organizing data in groups of the same trait. That could work.

Also I guess the static data thing I was referring to is called the Flyweight Pattern.
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU
Pages: 1 ... 540 541 [542] 543 544 ... 796