anyone wanna help me with a little C++ coding?

Page 4 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

ChefJoe

Platinum Member
Jan 5, 2002
2,506
0
0
If your ta told you about commenting and said it was required, you really should beef up yours. you can make your variable names real names and the counters can be random, but sequential single character names. you can make a comment key outlining.

Yes, it's sad... to make cs graders happy with your comments even these little programs will be 2 to 4X comments to code. I don't know how many times I lost major points on an otherwise perfect piece of code due to comments and early on, the points are easy, later - you'll be fighting to make your code compile and dealing with some of the really archane issues of c++ (there was one time I couldnt' compile the code and it was the order I was calling two distinctly different and unrelated variables... not sure why, but it turned out to be an issue).

http://www.cs.wisc.edu/~cs302/resources/guides/styleExample.html
 

GermyBoy

Banned
Jun 5, 2001
3,524
0
0
Try spacing it out like this.

#include <iostream.h>

int main()
{ //at this, indent one tab
cout << "Do everything here now.\n";
for (int walleye_pie = 0; walleye_pie < GermyBoys_coolness; walleye_pie++) //infinate loop
{
cout << "Notice the indentation.\n";
} //only at a close brace do we subtract one tab indention.
} //you'll see all of your errors this way.
 

xcript

Diamond Member
Apr 3, 2003
8,258
2
81
Originally posted by: GermyBoy
Try spacing it out like this.

#include <iostream.h>

int main()
{ //at this, indent one tab
cout << "Do everything here now.\n";
for (int walleye_pie = 0; walleye_pie < GermyBoys_coolness; walleye_pie++) //infinate loop
{
cout << "Notice the indentation.\n";
} //only at a close brace do we subtract one tab indention.
} //you'll see all of your errors this way.

Lol. Nice indentation guy. ;)
 

Apathetic

Platinum Member
Dec 23, 2002
2,587
6
81
OK, I'll try to give you some basic help.

First thing: loops

In C (or C++) a FOR loop has three parts. An initialization part, a test part, and an increment part - all of which are seperated by semicolons.

for (x = 0; x < 10; x++) {
cout << "Hi" << endl;
}

This loop will print "Hi" 10 times. We start by setting x to zero (the initialization part). Then it compares x to see if it is less than 10. If so, it executes the body of the loop once (the "cout"). After this, it executes the increment part (x++). It then retests the condition (x < 10) to see if the loop should run again.

The reason i mention all this is that your FOR loops seem to be missing a test condition and so they will run forever.

To answer one of your questions, a loop will execute once if the test condition tells it to execute only once. For example,

for (x = 0; x <=0; x++) {
// do something useful
}

^^^ This will execute exactly once.

I hope this helps.

Dave