Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Incoherence
May 22, 2004

POYO AND TEAR

Super Dude posted:

using erase(j) gives this error:

code:
error C2664: 'std::_Vector_iterator<_Ty,_Alloc>
 std::vector<_Ty>::erase(std::_Vector_iterator<_Ty,_Alloc>)'
 : cannot convert parameter 1 from 'int' to 'std::_Vector_iterator<_Ty,_Alloc>'1> 
erase takes an iterator parameter. You probably want alphabet.erase(alphabet.begin()+j). Why is it this hard? Because the STL is weird.

Adbot
ADBOT LOVES YOU

Incoherence
May 22, 2004

POYO AND TEAR

BraggPxnk posted:

drat, I was hoping there would be something a little easier than learning an API but oh well.

I was going to use it cross platform because my main computer is a Mac and all of my friends run windows. I wanted to make an 'application' so that I could make a little program just messing around and send it to them to use/make jokes about/help me improve my programming, stuff like that.

Well, I'll just start checking out some of these sites. Thanks.
The easiest way to do what you're describing is to switch to Java.

Incoherence
May 22, 2004

POYO AND TEAR

ShoulderDaemon posted:

I think the problem you're having is likely a problem very typical of new programming students: You think you understand what you want the computer to do, but you haven't yet set it down step by step, so you don't know how to program it. You're focusing on the "little" problems of your application instead of the "big picture", which makes everything more difficult because you aren't yet sure how the parts all need to fit together.
This is excellent advice, and if you read nothing else of his reply read that.

To say it another way, there are two steps involved in programming: specification (precisely stating what you want the program to do), and implementation (mapping that into code). New programmers often make the mistake of underestimating the former.

Incoherence
May 22, 2004

POYO AND TEAR

ShoulderDaemon posted:

code:
  // This die-rolling logic is a little bit complicated...
  // I'm trying to preserve exactly the "if two people have the same roll,
  // then only they reroll" behaviour.

  // First, I set each die as "not-yet-rolled", for which I use the value -1.
  for ( int i = 0; i < players; ++i )
    die[i] = -1;

  // Now, for each player, I roll a die...
  for ( int i = 0; i < players; ++i ) {

    if ( die[i] == -1 ) {
      // This player needs to roll.
      die[i] = random( ) % 20;
      fprintf( stdout, "Player %i rolled %i.\n", i + 1, die[i] + 1 );
    };

    // Check to see if this roll is the same as any other roll before it.
    for ( int j = 0; j < i; ++j ) {

      if ( die[i] == die[j] ) {
        // These players rolled the same, so they both need to reroll.
        fprintf( stdout, "Player %i has the same roll as player %i, so they both reroll.\n", i + 1, j + 1 );
        // This is probably the subtlest part of the code I've written.
        die[i] = -1;
        die[j] = -1;
        i = j - 1;
        break; // Goes back to the outer loop.
      };

    };

  };
I'm not convinced this is particularly fair (you resolve ties as they happen, instead of having everyone roll then resolving ties). Not that it terribly matters for this application, but you might get around this by having everyone roll once, then making another pass through the whole loop to resolve ties, and then you might end up doing the same thing again recursively... okay, never mind, we're getting way off the scope of Sarah Sherman's problem.

Incoherence
May 22, 2004

POYO AND TEAR

Viper2026 posted:

I changed the row/col size variables to type of size_t and now it lets me create the array given the values read in from my file. However, when I try to call my function:

cout << count_cells(the_grid[r_size][c_size], r_test, c_test) << "\n";

again, I'm getting this:

error: cannot convert 'color' to 'color (*)[5]' for argument '1' to 'int count_cells(color (*)[5], int, int)'
As mentioned before, the_grid[r_size][c_size] is a cell (which is why the compiler says it's of type color). Moreover, it's a cell that's not in the grid, so even if it compiled it would immediately segfault and you'd have even less feedback.

Go look at Paniolo's post again, particular the first code block.

Incoherence
May 22, 2004

POYO AND TEAR

Soldat posted:

Well, we've learned scheme and writing interpreters for it all semester and spent the last week or so in my intro class getting acquainted with c++. I suppose I didn't realize the level of coding that people expect questions to be asked about in this thread. I suppose I can take it to the yahoo! message boards or something. This is about my 8th program or so, if you include the several hello world! type ones that we did. I'm attempting the extra credit parts of a project where we haven't been introduced to classes yet, so thanks anyways for the code, but I can't use that. As I said, I'm a newbie. Thanks to those that were helpful.
For the record, until this post you were giving off the strong impression that you weren't a newbie. The people on this forum are more than capable of tailoring their advice to their perception of your skill level, but not if you aren't clear about what that is.

Incoherence
May 22, 2004

POYO AND TEAR
Your problem is an error in the logic of your setXroom() method. What you seem to want is for a.setnorthroom(&b) to set a.northroom = b and set b.southroom = a, but that's not what your code is doing at all. What setnorthroom() actually does when you call it in main() is that it sets adv.northroom AND adv.southroom to adv2, but does not change adv2.

Incoherence
May 22, 2004

POYO AND TEAR

chutwig posted:

Most of my confusion originates in what I perceive to be counterintuitive syntax by C. When you write something like char *blah, if you're reading it left to right, you initially think it's a variable of type char, and then have to reset mentally and re-read it as a pointer pointing to something of type char. I feel that syntax such as "&char blah", which could be read "address-of-char", would have been a more intuitive way to declare a pointer.
This is the motivation behind the use of char* blah, since it makes it more obvious that blah is of type pointer-to-char instead of char. The only reason it's not more prevalent is that if you type char* a, b, c;, a is a pointer, but b and c are not.

And yes, the overloading of the * operator is fairly obnoxious, but then again I could say the same about the . operator in Java.

Incoherence
May 22, 2004

POYO AND TEAR

Zombywuf posted:

Wrong wrong wrong, bad and wrong. auto_ptr defines ownership of heap objects and will defend you from the problems of memory leaks caused by exceptions they complain about elsewhere.
The implication is that scoped_ptr is used instead; given the aversion to copying seen elsewhere, this makes some sense.

quote:

I think most of the rebuttal to to those style guidelines is "Don't hire Java programmers to do C++."
Java programmers would be using exceptions. :v:

Incoherence
May 22, 2004

POYO AND TEAR

sarehu posted:

That's not true. You can write a program that takes the state of any given computer and tells whether a program on it will halt.
While the amount of state in a computer (not a Turing machine) is technically finite, it'd still take a very long time to either determine that it halts or that it cycles (which is equivalent to it not halting).

Incoherence
May 22, 2004

POYO AND TEAR

Avenging Dentist posted:

And it's more important to get people in the habit of considering the concept of RAII when writing C++. :colbert:
It helps if you know what RAII is supposed to do when you write your own objects, which implies that you know how to free resources when you no longer need them.

Adbot
ADBOT LOVES YOU

Incoherence
May 22, 2004

POYO AND TEAR

Anunnaki posted:

I'm working on an assignment for my C++ class (instructions here). I've got everything working so far, except the output for the maximum profit, its ticket cost and number of passengers.

I don't know how I would go about having the program collect that information. I'm thinking maybe it has to scan all the output, find the highest value in profit, and assign it, its ticket price, and number of passengers to their own variables. I'm not sure. Does anyone have any ideas?
You're calculating profit for each value of number of passengers/ticket cost already in your "Output" loop. Just keep a running maximum while you do that: start with your maximum so far being 0, and if the profit in a particular iteration of the loop is more than the maximum so far, save aside that maximum profit/number of passengers in a different set of variables.

(I'm not going to give you code because this is a class assignment and I'm not going to do ALL of your homework for you.)

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply