jrfootball13,
Please use code tags (the <>button when creating a post) to put your code in. It helps us tell which stuff is code and which is not. A couple of links on how to use code tags:
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
First of all, your program isn't very readable, although it's better than a lot I've seen. It's always a good idea to use plenty of whitespace– empty lines separating chunks of code, and indenting code within braces.
e.g.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include <iostream>
int main ()
{
// thing
while (/*condition*/)
{
// stuff happens
}
std::cout << "Hello world" << std::endl;
return 0;
}
| |
See? Lots of whitespace and indenting makes it easier to read code in chunks that can be visually broken down and processed.
Using plenty of comments like you did is good though, so brownie points for that ;)
Onto more relevant stuff, when I compiled your code in Clang, I got this:
$ c++ -g -Wall -Wextra -pedantic -o code_words code_words.cc
code_words.cc:44:1: error: no matching function for call to 'shuffle'
shuffle(WORDS.begin(), WORDS.end(), std::default_random_engine(seed));
^~~~~~~
/Library/Developer/CommandLineTools/usr/include/c++/v1/algorithm:3282:10: note: candidate function
[with _RandomAccessIterator = std::__1::__wrap_iter<std::__1::basic_string<char> *>,
_UniformRandomNumberGenerator = std::__1::linear_congruential_engine<unsigned int, 48271, 0,
2147483647>] not viable: expects an l-value for 3rd argument
void shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
^
code_words.cc:63:8: warning: expression result unused [-Wunused-value]
nomore - wrong++;
~~~~~~ ^ ~~~~~~~
code_words.cc:124:8: warning: ISO C++ does not allow 'main' to be used by a program [-Wmain]
return main();
^
code_words.cc:144:2: warning: no newline at end of file [-Wnewline-eof]
}
^
code_words.cc:93:19: warning: comparison of integers of different signs: 'int' and
'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>
>::size_type' (aka 'unsigned long') [-Wsign-compare]
for (int i = 0; i < THE_WORD1.length(); ++i)
~ ^ ~~~~~~~~~~~~~~~~~~
4 warnings and 1 error generated. |
Ok, that's not good.
Note: I copied and pasted your code into my code editor, so the line numbers should be correct.
The error– no matching function for call to "shuffle." Well, you included
<algorithm>, and it looks like you did all the parameters right. I don't know, maybe my algorithm file is screwed up. Does it compile OK for you?
First warning. Uh, what...
1 2
|
// Increment the number of incorrect guesses the recruit has made
nomore - wrong++;
| |
I've never seen anyone do this before. That just will not work. Did you mean
nomore = wrong++;
?
Second warning. What is this?
118 119 120 121 122 123 124 125
|
if (playagain == 'Y' || playagain == 'y')
{
counter++;
// Increment the number of simulations ran counter
cout << "You are now on simulation " << counter++ << "\n";
// Move program execution back up to // Display the simulation # is starting to the recruit
return main();
}
| |
You're...returning
main()? Why? That doesn't work. And you don't need it. The program will automatically go on to whatever is after the
else statements after it.
Third warning. Uh, ok, that's stupid, seriously. I don't even know why that is a warning...?
Fourth warning. Ok, you're comparing an
int and an
unsigned long...with different signs? That doesn't sound like a big deal. Try making the "
int i" into an "
unsigned i" and see if that gets rid of it.
Well, I hope this gives you something to start with!
max