Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 528 529 [530] 531 532 ... 796

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

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7935 on: September 23, 2015, 09:58:11 pm »

I can do if statements fine and I know how they work but for some reason I can't get my else if statements to plug in with the rest.
You've got a } in the wrong place. The } below "cin >> radiusC;" causes "if (menuOption == 1)" to end, meaning "if (radiusC < 0)" is outside. This means it's running no matter what your menu option, which means it's getting uninitialized garbage values if you didn't choose 1.

Edit: Ispil explains it better.
« Last Edit: September 23, 2015, 10:03:28 pm by Bumber »
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7936 on: September 23, 2015, 10:37:38 pm »

oh, oops, yeah, that's actually the cause of your immediate problem
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 #7937 on: September 23, 2015, 10:50:49 pm »

You must use the operator ==, not =, for conditions.

= is the assignment operator. What's happening is that your code is that you get to the if statement, then it evaluates the condition you give it. The operator returns 1 because it succeeded, and C++ (at least if C is anything to go by) treats any nonzero value as True when you use it as a boolean (a boolean is a data type that can only have the values True or False). At least that's what I think the reason for that behavior is, but the thing I know is that you'll get wacky results with this typo.

== is the comparison operator, and it returns True if the two things you hand it are equal, and False otherwise.

You had it right the last time, so I don't know why you changed it.

This bit that you gave me:

Spoiler (click to show/hide)

or this one

Spoiler (click to show/hide)

EDIT: Sorry clicked the glow thing by accident during a freeze on my pc.
« Last Edit: September 23, 2015, 10:57:38 pm by 3man75 »
Logged

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7938 on: September 23, 2015, 11:02:49 pm »

Thanks. I'll be working on it so more tommorow. It's 12 o'clock and I need rest before I tackle this again.
Logged

Dutrius

  • Bay Watcher
  • No longer extremely unavailable!
    • View Profile
    • Arcanus Technica
Re: if self.isCoder(): post() #Programming Thread
« Reply #7939 on: September 24, 2015, 11:30:17 am »

Code: [Select]
public int Recursion()
{
    return Recursion();
}

Sorry, I just had to share that.
Logged
No longer extremely unavailable!
Sig text
ArcTech: Incursus. On hold indefinitely.

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #7940 on: September 24, 2015, 12:57:28 pm »

I was making a Game of Life program to practice programming in C for my operating systems class (where we're required to use C exclusively), and I decided to try and use an unbounded 2D plane instead of defining a size for it. My solution was to store the coordinates of all living cells rather than all the cell states in the defined area, so it doesn't matter how far they go (practically). But I just realized I have a problem.

Is there a C standard library equivalent of std::set? I prototyped my idea in C++ and it works fine, but unless there is an equivalent in C I guess I'll have to write my own... which also brings up the problem that I'll need to write my own hash-based comparison function for 2D coordinates. I've never quite figured out a way to do that.

I'm using the unix standard library.
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

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7941 on: September 24, 2015, 01:36:51 pm »

Gatleos could you send me your code to try it out on my compiler? I'm interested in how a 'game of life' works. By the way what school do you go to that mandates using C only? I've heard that C++ was old but still taught as a way to help introduce Java later on. Is C still being used for research or some behind the scenes stuff?
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7942 on: September 24, 2015, 01:51:49 pm »

Gatleos could you send me your code to try it out on my compiler? I'm interested in how a 'game of life' works. By the way what school do you go to that mandates using C only? I've heard that C++ was old but still taught as a way to help introduce Java later on. Is C still being used for research or some behind the scenes stuff?

Conway's Game of Life is this, and here's a very good Life engine you can have a look at.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7943 on: September 24, 2015, 01:58:32 pm »

IMO, Java and C++ are both just awful for learning programming. C++ because of the fairly long development pipeline compared to some simpler languages, Java because of all the damn boilerplate.

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7944 on: September 24, 2015, 02:04:03 pm »

C is still commonly used in embedded systems work in the real world as well as tons of other lower level things (such as operating systems). (And for what it's worth, any C program will compile in C++ as well). C++ as is is still an excellent language to learn, currently being the 3rd most commonly used language (being beaten by plain old C and by Java, which has been in a slow and steady decline for years now).

Really the only "obsolete" languages you'll ever run into as a computer person are some of the ones that were developed back in like the 40's (and even some of those are still viable, having been updated tons since then).
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.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7945 on: September 24, 2015, 02:09:56 pm »

C++ is not used to help learn Java. That's almost certainly 100% reversed from the way things actually work. It's actually pretty hilarious to think anyone thinks that C++ is a beginners "learning" language as a stepping-stone to learning Java. In Lego terms, that would be like saying you bought a Lego Mindstorm Robotics kit as a way to help you learn how to use Duplo :D

C++ first could make sense, but in the learning-to-drive sense that learning on a manual means you can do both, whereas learning on an automatic transmission means you might get into lazy bad habits. But the reason isn't to ease-into automatic driving, the reason is so that you can use the manual transmission when needed. Race cars are manual transmission. C++ is the Formula One car of programming, superfast but hard to control.

Java: runs slow, but simple syntax, and works on interpreters on any machine, so you can deploy it via the web. It's used for stuff where you don't really care about performance.

C++: runs really fast, but much more knowledge required, and needs to be compiled separately for each target operating system. It's used for high-performance areas, such as games development and simulations.
« Last Edit: September 24, 2015, 02:20:56 pm by Reelya »
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7946 on: September 24, 2015, 02:31:03 pm »

C is still commonly used in embedded systems work in the real world as well as tons of other lower level things (such as operating systems). (And for what it's worth, any C program will compile in C++ as well). C++ as is is still an excellent language to learn, currently being the 3rd most commonly used language (being beaten by plain old C and by Java, which has been in a slow and steady decline for years now).

Really the only "obsolete" languages you'll ever run into as a computer person are some of the ones that were developed back in like the 40's (and even some of those are still viable, having been updated tons since then).

I said it's awful to learn programming, not to learn.

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7947 on: September 24, 2015, 02:37:11 pm »

Reelya if you could tell me what a Duplo is i'm doing it wrong? Dammit my proffesors lied to me!

Oh well. C++ to me is either really great once you can get to understanding it or a pain with all of its ultra precison in complicated synthax. I.E

cout <<
cin >>

I learned the signals by heart imagining a racecars going outside a tunnel or inside with those two. Not hard but when you add..

pow(x,y) where x and y can be heavilly modified and can have extra parenthesis.

Nesting If's has also been troublesome because I was given the logic to 'connect the if's like you would blocks' instead of stuffing them in together.

Previous believed this:

Block of if 1
--------------------separated but connected.
Block of if 2.

Instead of:

Block 1 (

Block 2()

)

Thanks for the racecar analogy on fast racecars i'll be sure to tell my friends tomorrow after class.

C is still commonly used in embedded systems work in the real world as well as tons of other lower level things (such as operating systems). (And for what it's worth, any C program will compile in C++ as well). C++ as is is still an excellent language to learn, currently being the 3rd most commonly used language (being beaten by plain old C and by Java, which has been in a slow and steady decline for years now).

Really the only "obsolete" languages you'll ever run into as a computer person are some of the ones that were developed back in like the 40's (and even some of those are still viable, having been updated tons since then).

I said it's awful to learn programming, not to learn.

To me it feels great and optimistic once you actually get the concepts but a pain to implement them not learn them.
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7948 on: September 24, 2015, 03:34:34 pm »

3man, I think you really aren't getting the concept of what a program is. It's just a list of instructions for a computer. If someone gave you a list of instructions, how would you do them? You'd do them one by one, starting from the top, then going to the bottom. Computers do just the same.

Now let's say there's an instruction that says "Is your number bigger than four? If yes, then do the instructions in these braces, but if no, then skip them". This is exactly what an if statement does. "If your number is bigger than four, then do the instructions in these braces, otherwise skip them".
Logged

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7949 on: September 24, 2015, 03:38:49 pm »

Race cars are manual transmission. C++ is the Formula One car of programming, superfast but hard to control.
Probably not the best analogy anymore. :P Nowdays automatic transmissions have gotten so good that they are actually better than humans in most cases now, and as such it's now a 5/2 ratio... in favor of automatic/double transmissions. Technology marches on and all that jazz. :P

I said it's awful to learn programming, not to learn.
Sorry, my statement was more aimed at the "C++ is only good as a learning stone for Java" comment, not at your post. XD
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.
Pages: 1 ... 528 529 [530] 531 532 ... 796