Public Group

This topic is 3309 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Share on other sites
P.S. sorry some of the things are in caps lock im going threw to change them soon

Share on other sites
Ok, first thing:
/source tags for your code. It makes it musch easier to read.
Second: You never defined 'PLAYAGAIN' as and interger or boolean.

Share on other sites
so do you mean i should type
int PLAYAGAIN ()

if so where at?

Share on other sites
i thought it was being used for like, at the end if they say "yes" that they want to play again it was using bool play

and i updated my code above so u can look at it again

Share on other sites
now im geting an error called
error C2446: '==' : no conversion from 'const char *' to 'int (__cdecl *)(void)'

Where is that?

Share on other sites
Let us look at this carefully. First, lets make sure we understand what the compiler means. What is an "undeclared identifier". Well, C++ has many rules, one of which is that you must tell C++ about something before you use it.

Its like if I said: "Yeah, so I was hanging out with Jenny yesterday and...". If I never mentioned "Jenny" before, you would probably interrupt me there and then and say "Who is Jenny"?

So the compiler is asking: "what is PLAYAGAIN", or more precisely, "what type is PLAYAGAIN".

Let us look at the code. Here is everything before main:
#include <iostream>#include <string>#include <stdlib.h>#include <time.h>using namespace std;int DICEROLL();int INTROSCREEN();void RETRY();void WIN();int BEARTOTAL;int DICENUMBER;int USERANSWER;int TOTALCORRECT;string NAME;bool PLAY = true;

No mention of PLAYAGAIN yet.

Now the first few lines of main (indentation added)
void main (){    srand((unsigned)time(NULL));    while (PLAYAGAIN == "yes")        INTROSCREEN ();        // ...}

Ok, so the compiler sees you trying to use something called PLAYAGAIN, without you giving it any clues about it.

Two lines later you do tell it, but its too late, the compiler has already rejected your program. Conversations with people are a bit more lenient [smile]

The solution is to move the declaration of PLAYAGAIN to before the loop:
void main (){    srand((unsigned)time(NULL));    string PLAYAGAIN = "yes";    while (PLAYAGAIN == "yes")        INTROSCREEN ();        // ...}

• The function "main" should return an int, it is not a void function.

• The outer loop in main() lacks curly brackets. If you write a loop without using curly brackets, only the first line is considered part of the loop. So you essentially wrote: "while playagain equals yes, introscreen()", which probably isn't what you wanted.

• You can avoid writing function declarations by moving some of your functions before main()

• Global variables (ones declared outside a function) are generally not a good idea. Instead, see if you can pass information to functions in their parameter lists and you can use the return keyword to send information back from a function.

As an example, consider a "retry" function:
// This function returns "true" if the player wants to retry.// Other wise it returns "false".// It will try again if it gets input it doesn't understand//bool retry(){    // keep looping until they give us an answer!    while(true)    {        cout << "Want to play again? (yes or no)" << endl;        string answer;        cin >> answer;        // use "else" when two conditions are mutually exclusive.        if (answer == "no")        {            return false;        }        else if(answer == "yes")        {            return true;        }        else        {            cout << "I'm sorry, I didn't understand your answer: " << answer << endl;        }    }}

Other code can use the information like this:
// keep playing while the user says they want to retry:do{    playGame();}while( retry() );

• The old C headers are called cwhatever, not whatever.h. So instead of <stdlib.h>, we use <cstdlib> and for <time.h> we use <ctime>.
• You have a switch statement where a number of the cases are identical. See if you can use the "default" case instead to handle these.

• You can see that when I posted code, I got a box with some nice colouring, at the same time the indentation of the code was preserved. You can do this too, by using these tags when writing your posts. You can go back and edit your original post to include them, though you will need to copy and paste your code back in to fix the indentation.

• Caps are awful hard to read. Try replace them ASAP [smile]

Share on other sites
ok i think im understanding, i am changing and updating the code above with changes, please look at it

• 9
• 23
• 10
• 19