Talk About Network

Google





Programming > C - C++ Learning > Re: beginer pro...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 6 Topic 4062 of 4400
Post > Topic >>

Re: beginer programer needs help

by "Jim Langston" <tazmaster@[EMAIL PROTECTED] > Mar 10, 2008 at 01:18 PM

Justice wrote:
> I am trying to make a simple game but have some problems
>
> here is the code so far
>
[SNIP]
>
> int main()
> {
>
[SNIP]
> player Main; // CREATE MAIN CHAR
[SNIP]
> cout << "Would you like to visit the store? ";
> cin >> Store;
> if (Store='y')
> {
>
> STORE(Gold);
> }
[SNIP]
>
> return 0;
> }
[SNIP]
> void STORE(int Gold)
> {
> char Buy;
> int Item;
> char Sell;
> string Wepon;
> string armor;
>
> system ("cls");
> cout << "We have " << endl;
> cout << "1 - Dagger----------------50 gp" << endl;
> cout << "2 - Short Sword----------100 gp" << endl;
> cout << "3 - Long Sword-----------150 gp" << endl;
> cout << "4 - Leather Armor--------200 gp" << endl;
> cout << "5 - Sheld-----------------50 gp" << endl;
>
> cout << "Would you like to buy anyting?(y/n)" << endl;
> cin >> Buy;
> if (Buy='y')
> {
> cout << "what would you like" << endl;
> cin >> Item;
> PURCHICE(Item);
> }
> else
> {
> cout << "Would you like to sell anything" << endl;
> cin >> Sell;
> if (Sell='y')
> {
> Wepon=Main.DISPLAY_WEPON();
> Armor=Main.DISPLAY_ARMOR();
> cout << "What would you like to sell" << endl;
> cout << "1 - " << Wepon << endl;
> cout << "2 - " << Armor << endl;
> cin >> Item;
> SELL(Item);
> }
> }
>
> }
>
>
> --------------------Configuration: GAMEv001 - Win32
> Debug--------------------
> Compiling...
> gamev001.cpp
> c:\do***ents and settings\justice\gamev001\gamev001.cpp(345) : error
> C2065: 'Main' : undeclared identifier

This is what I tried to show by snipping unrelated code.  The variable
Main 
is declaired in the function main().  It is therefor local to the function

main.  Outside of main it doesn't exist.

Your function Store attempts to use the variable Main, but Main doesn't 
exist in it.  One way to make Store see Main is to pass it as a parameter.

Since you'll be wanting to change Main you'll want to pass a reference to 
it.  So, change the signature of Store:

void STORE(player& Main, int Gold)

and in main call STORE like:

STORE(Main, Gold);

This is the main error I found, but looking at your other errors, you 
probably have to do the same thing with Armor, pass it in.

> c:\do***ents and settings\justice\gamev001\gamev001.cpp(345) : error
> C2228: left of '.DISPLAY_WEPON' must have class/struct/union type
> c:\do***ents and settings\justice\gamev001\gamev001.cpp(346) : error
> C2065: 'Armor' : undeclared identifier
> c:\do***ents and settings\justice\gamev001\gamev001.cpp(346) : error
> C2228: left of '.DISPLAY_ARMOR' must have class/struct/union type
> Error executing cl.exe.
>
> GAMEv001.exe - 4 error(s), 0 warning(s)



-- 
Jim Langston
tazmaster@[EMAIL PROTECTED]

 




 6 Posts in Topic:
beginer programer needs help
Justice <foisys@[EMAIL  2008-03-10 11:33:59 
Re: beginer programer needs help
"Jim Langston"   2008-03-10 13:18:47 
Re: beginer programer needs help
Justice <foisys@[EMAIL  2008-03-10 15:02:46 
Re: beginer programer needs help
Triple-DES <DenPlettfr  2008-03-11 00:19:37 
Re: beginer programer needs help
Justice <foisys@[EMAIL  2008-03-11 06:40:25 
Re: beginer programer needs help
Ben Cottrell <bench@[E  2008-03-11 13:47:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Wed Jan 7 14:06:18 PST 2009.