This topic is 3218 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

##### Share on other sites
okay changed the order of those as u sugested.

heres one of the erros im having

: error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'int (__cdecl *)(void)' (or there is no acceptable conversion)

(theres a long list of errors this is like the first one)

##### Share on other sites
kk ty i fixed alot of the caps, sorry about those i know its rather anoying.
i was just used to doing it because examples for class used caps for some reason

please stay with me for a lil im fixing everything i see u mention , im puting the c infront of those now , refresh ur page ina sec

##### Share on other sites
awsome that took away almost all of the errors! =)

okay this is the only error im having now

fatal error C1083: Cannot open include file: 'cstdlib.h': No such file or directory

O_O what now?

##### Share on other sites
Quote:
 Original post by Lorraine_Bnow im geting an error callederror C2446: '==' : no conversion from 'const char *' to 'int (__cdecl *)(void)'

This is a far more cryptic error, especially for a beginner. Essentially, it means "I cannot compare a string and a function". A string literal (something in quotes) is of type const char *, and a function have their own type, which is related to how they are declared.

Any function has this form:
<return-type> <name> ( <argument-list> ) ;

You can see that "int (__cdecl *)(void)" looks quite similar to that, "int" is the return type and "void" means that the argument list is empty. The second set of parentheses, with "__cdecl *" inside them, are beyond this discussion, but again they are more clues that the type is a function.

A correct declaration of your string is this:
string PLAYAGAIN;

Although you would have to initialise it to "yes" for your program to work. However, as I showed in my earlier post, this variable can be local to main (or eliminated entirely) by rewriting your RETRY function.

##### Share on other sites
Quote:
 Original post by Lorraine_Bawsome that took away almost all of the errors! =)okay this is the only error im having nowfatal error C1083: Cannot open include file: 'cstdlib.h': No such file or directoryO_O what now?

Read it again, a little more carefully:
Quote:
 The old C headers are called cwhatever, not whatever.h. So instead of , we use and for we use .

C++ standard library headers do not have a ".h" extension.

And don't forget to check the link I gave about forum tags. You can use [source] and [/source] around your code to put them in the scrolling, syntax highlighted box.

##### Share on other sites
ohhhh i see, ohay i fixed that and updated the code

now im getting this error

fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\owner\my documents\visual studio 2005\projects\ice and dice\ice and dice\icendice.cpp(198)' was matched

O.o

by the way i put that source and /source in so now it made the page smaller =)

##### Share on other sites
We can't fix your code for you, that is against the forum rules on homework.

The error message is pretty self explanatory. The reference to "198" in the error message is the line number. So go to line 198 and look for an opening curly brace. The error says that when the compiler was looking for the corresponding closing brace, it reached the end of the file.

Other than that, you may want to copy and paste your code from your IDE again as it has been mangled by the transformation into HTML.

Next time you get an error message, try googling the error code. This will tell you more about what the error means. Here, the error code is "C1075". If you can't figure out the error message means, try include something about what you think it might mean next time you post. Don't worry about being wrong.

Learning to decipher error messages is an important skill, so best to practise.

##### Share on other sites
it doesnt say next to it what line it is

##### Share on other sites
Quote:
 Original post by Lorraine_Bit doesnt say next to it what line it is

In the editor?

Assuming MSVC, go to "tools, options, text editor, all languages, general" and tick the "show line numbers" setting. I would have thought that line numbers would be enabled by default.

But you can just click on the error message and it will jump to the line involved.

##### Share on other sites
awsome thanks so much, i got the numbers to come up so i know where line 198 is now

thanks alot i really apreiciate it. i didnt ant to come here for someone to do my homework for me i just couldnt figure htis out on my own, you know? so thanks for explaining alot of things to me! =)

ill keep working at it and see if i can get it to work ^^

##### Share on other sites
Quote:
 Original post by Lorraine_Bawsome thanks so much, i got the numbers to come up so i know where line 198 is now

No problem!

Quote:
 thanks alot i really apreiciate it. i didnt ant to come here for someone to do my homework for me i just couldnt figure htis out on my own, you know? so thanks for explaining alot of things to me! =)

I understand. I have to say that compiler writers do seem to go out of their way to make the errors cryptic and difficult to understand. Even a C++ veteran can get a lost when they try compile some template wizardry and the compiler takes exception to it and chokes on a few hundred lines of dense error messages.

Just don't forget about some of the advice I gave in my first reply. Your latest edit doesn't appear to have taken it all in, some of it is extremely important.
Quote:
 ill keep working at it and see if i can get it to work ^^

Good luck with getting your program to work.