I have a quick question about posting. I am retaking over my final C++ class and still have the programs from the class. Even thought the class is a month away I am planning on working on them early. Would there be anything wrong with posting about each piece of the assignment and just a slow steady walkthrough just to make sure I do everything right and have ample time to complete?

I don't want to speak for anyone else, but rather than having someone do an entire walkthrough of your code, you could pick out sections that are problematic, and post those. Someone is much more inclined to wade through 20-50 lines rather than a few hundred.

If you have large scale problems like "why the heck can't I get input from a file on days ending in 'y'?" then google around for some solid tutorials and take yourself through them (since you'll have less code to write from scratch) and try to learn those techniques through 1-2 of the assignments rather than posting every single one that requires that technique.

sounds good one quick follow up question...If I post my code my last yr for this program can someone at least kind of show me just what I should get rid of so I have somethig to start with?

You can certainly post whatever you like. I was just stating that a ton of code is less likely to be read by most people. This is an ideal chance for you to learn to use a debugger (or the poor man's debugger using cout statements) and figure out where things are going wrong. Start small, make a fresh file and cut and paste small portions of it in, compile it, test it, if it works, paste more in there.

I suggest you think about coding as being a lot like putting together a puzzle. First you assemble the edges/frame, then you fill in the middle until you get the final image. During the process, you need to make sure that every piece you add works with the rest of the pieces.

Let's say you need a program that inputs numbers then outputs the average. First, get your "frame" in place:

#include <iostream>
using std::cout;
using std::endl;
using std::cin;

int main() {
  return 0;
}

Compile it so you know this is a working program. Once you know it works, start filling it in little by little. Maybe your next step would be to add an input loop and display each number you input:

#include <iostream>
using std::cout;
using std::endl;
using std::cin;

const int SENTINEL = -1;                                     //new constant

int main() {
  int inputValue = SENTINEL;                                 //new variable

  cout << "Please enter a non-negative number:";             //new prompt
  cin >> inputValue;

  while (inputValue > SENTINEL) {                            //new loop
    cout << "You input the number " << inputValue << endl;
    cout << "Please enter a non-negative number: ";
    cin >> inputValue;
  }

  cout << "Sentinel value detected, ending program." << endl; //new output

  return 0;
}

Then, continue in this fashion until you have all the "pieces" in place. Perhaps next add the code necessary to accumulate and display the sum. Then add an input counter and associated display, then add the code necessary to calculate and display the average.

Edited 5 Years Ago by Fbody: n/a

If you want a general code review, be sure to ask for it specifically to avoid confusion. I and a few others occasionally tear down programs line by line, point out issues, and suggest better ways of going about a solution, but it's ideal if the program is relatively short because those reviews get kind of long.

I'm not sure how long your assignments are, but it never hurts to ask.

This article has been dead for over six months. Start a new discussion instead.