ToySoldier 0 Newbie Poster

What (or who) I need is a guide though.

If anyone has an example of their own game it would be very helpful for me if you could send it over so I can check out the source code and get into the game programmers mind.
Please help, thanks in advance :cheesy:

I dont know how good the book is...I'm sure you can read reviews on Amazon.com but maybe this is a good start?

Beginning Game Programming: $23.09
Product Details
Paperback: 624 pages
Publisher: Sams; Bk&CD-Rom edition (July 19, 2004)
Language: English
ISBN: 0672326590

Book description from publisher's homepage:

If you are hooked on video games and have a basic knowledge of C++ and visual programming, you will be hooked on Beginning Game Programming. Clear, practical lessons based on C++ programming are the basis of this book's lessons. By focusing on the Windows API to construct games, you will learn game theory in double-buffered graphics, sprite animation, digitized sound effects and music. A fully functional game engine provided on CD, along with tools, code and graphics, will give you the ability to create your own games in the future. Learn the art and science of game programming with help from Beginning Game Programming.

Here is another informational link:
http://www.toymaker.info/Games/html/beginners.html

ToySoldier 0 Newbie Poster

I dont know how good the book is...I'm sure you can read reviews on Amazon.com but maybe this is a good start?

Beginning Game Programming
Price: $23.09

Book description from publisher's homepage:

If you are hooked on video games and have a basic knowledge of C++ and visual programming, you will be hooked on Beginning Game Programming. Clear, practical lessons based on C++ programming are the basis of this book's lessons. By focusing on the Windows API to construct games, you will learn game theory in double-buffered graphics, sprite animation, digitized sound effects and music. A fully functional game engine provided on CD, along with tools, code and graphics, will give you the ability to create your own games in the future. Learn the art and science of game programming with help from Beginning Game Programming.

I found another link that answers what your asking as well:
http://www.toymaker.info/Games/html/beginners.html

ToySoldier 0 Newbie Poster

Thanks... cleaned it up and turned it in.

Gonna take my time with our next program.

ToySoldier 0 Newbie Poster

Been working on this project for last 2 nights. Cant get rid of this error message on my last method PAIR::area() . It's defined at the bottom of my program.

Everything else compiles... builds... executes just fine. Rusty on the basics and trying to figure out methods.... here is my error message:

error C2601: 'area' : local function definitions are illegal
Error executing cl.exe.

It sounds obvious but I think I'm just a little blurry eyed. Project is due tonight (Thur) at 6pm. I think I need to go start at chapter one again It's has to be something dumb I'm doing.

Any help appreciated.

class PAIR
 
{private:
 int a;
 int b;
 
public:
 
 void print();
 PAIR();
 PAIR(int);
 PAIR(int,int);
 ~PAIR();

 void swap();
 int diff();
 int big();
 int area();
};

int main()
{
PAIR c, d(2), e(12,13);

int ans;
c.print();
d.print();
e.print();


d.swap();
d.print();
e.swap();
e.print();

ans = c.diff();
cout << "\nThe answer to c.diff() is  " << ans << endl;

int big = e.big () ;
cout << "\nThe larger number of e.big() is  " << big << endl << endl;

return 0;
}

PAIR::PAIR() 
{
a = 2;
b = 3;
}

void PAIR::print()
{cout << a << " " << b << endl;}

PAIR:: ~PAIR()
{
  cout << "Display Destructor Message" << endl;
}

PAIR::PAIR(int p1)
{a=p1;
b=p1;}

PAIR::PAIR(int p1,int p2)
{
a=p1;
b=p2;
}

void PAIR::swap()
{
 int c;
 c=a;
 a=b;
 b=c;
}

int PAIR::diff()
{
	return b - a;
}

int …
ToySoldier 0 Newbie Poster

Thanks... I'll try it out.

ToySoldier 0 Newbie Poster

Hi,

Appreciate any help. My code compiles... builds.... executes just fine. Only problem I'm having is... I cant figure out how to get PAIR::big() to simply print out the larger #. When I execute... it displays... the Larger # like I want... but then for some reason it displays the smaller number next to it. I want to get rid of the smaller #.

Any suggestions?

Thanks Mike

#include <iostream>
using namespace std;
 
class PAIR
 
{
private:
 int a;
 int b;
 
public:
 
 void print();
 PAIR();
 PAIR(int);
 PAIR(int,int);
 ~PAIR();

 void swap();
 int diff();
 int big();
 int area();
};

int main()
{
PAIR c, d(2), e(12,13);

int ans;
c.print();
d.print();
e.print();

e.swap();
e.print();

ans = c.diff();
cout << ans << endl;

e.big();
e.print();

return 0;
}

PAIR::PAIR() 
{
a = 2;
b= 3;
}

void PAIR::print()
{
cout << a << " " << b << endl;
}

PAIR:: ~PAIR()
{
cout << "Display Destructor Message" << endl;
}

PAIR::PAIR(int p1)
{
a=p1;
b=p1;
}

PAIR::PAIR(int p1,int p2)
{
a=p1;
b=p2;
}

void PAIR::swap()
{
 int c;
 c=a;
 a=b;
 b=c;
}

int PAIR::diff()
{
return b - a;
}

int PAIR::big()
{
if (a > b)
{
return a;
}

else 
{
return b;
}
}
ToySoldier 0 Newbie Poster

Avoid loop control using eof.

Thanks. I didnt quite understand why that was bad code. I will read your hyperlink in detail.

I like surprising the Prof with stuff like that and backing it up. I also found out with messing with my assignment why \t can get you in trouble... it was messing up my COUT formatting. I had to redo the COUT and OUTPUT statements with setw in order for it format properly.

ToySoldier 0 Newbie Poster

I figured out my "UNKNOWN" state name problem with the following code. I've posted my correct code for anyone needing an example of a Parallel Array.

Now it's time to tackle my CLASSES assignment...

while (!infile.eof())
{st_name="UNKNOWN";
for(int x=0; x<10; x++)

{if(st_code==st_codes[x])
{st_name=st_names[x];}
}

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

ofstream outfile;
ifstream infile;

int main()
{
string first, last, ss, st_code, st_name;

string st_codes [10]={"AL","CA","FL","GA","IA","KS","MO","MI","MS","NM"};
string st_names [10]={"Alabama", "California", "Florida", "Georgia",
					  "Iowa", "Kansas", "Missouri", "Michigan", "Mississippi", "New Mexico"};

outfile.open("report31.txt");
if(!outfile) {cout<< "TEST"<<endl; return 0;}

cout <<"\t\t\t\t"<<"PEOPLE REPORT\n";
cout <<"\t\t\t\t"<<"  FALL 2005\n\n";
cout <<"FIRST"<<"\t\t"<<"LAST"<<"\t\t"<<"SS"<<"\t\t"<<"STATE"<<"\t\t"<<"STATE\n";
cout <<"NAME"<<"\t\t"<<"NAME"<<"\t\t"<<"NUMBER"<<"\t\t"<<"CODE"<<"\t\t"<<"NAME\n\n";

outfile<<"\t\t\t\t"<<"PEOPLE REPORT\n";
outfile<<"\t\t\t\t"<<"  FALL 2005\n\n";
outfile<<"FIRST"<<"\t\t"<<"LAST"<<"\t\t"<<"SS"<<"\t\t"<<"STATE"<<"\t\t"<<"STATE\n";
outfile<<"NAME"<<"\t\t"<<"NAME"<<"\t\t"<<"NUMBER"<<"\t\t"<<"CODE"<<"\t\t"<<"NAME\n\n";

infile.open("people3.txt");

infile>>first>>last>>ss>>st_code;

while (!infile.eof())

{st_name="UNKNOWN";
	for(int x=0; x<10; x++)
	
	{if(st_code==st_codes[x]) 
	{st_name=st_names[x];}	
	}
 
	cout<<left<<setw(16)<<first<<left<<setw(16)<<last<<left<<setw(17)
		<<ss<<left<<setw(15)<<st_code<<st_name<<endl;
 
	outfile<<left<<setw(16)<<first<<left<<setw(16)<<last<<left<<setw(17)
		<<ss<<left<<setw(15)<<st_code<<st_name<<endl;

infile>>first>>last>>ss>>st_code;


}
return 0;
}
ToySoldier 0 Newbie Poster

Do this:

while ( infile>>first>>last>>ss>>st_code )
   {
      for ( int x=0; x<10; x++ )
      {
         if ( st_code==st_codes[x] )
         {
            st_name=st_names[x];
            break;
         }
      }

Should I use the break command to insert the "UNKNOWN" for a state name? I'll mess around with it. Thanks...

ToySoldier 0 Newbie Poster

Change the last line of your while loop to this

infile>>first>>last>>ss>>st_code;

Wow... that did the trick. I now see that I was asking the infile to find something that wasnt there. Thanks.

I'll now focus on getting state codes AA, ZZ, X1 to COUT "UNKNOWN". It looks like an easy thing to do but I'll try and walk thru it with my correct output.

ToySoldier 0 Newbie Poster

Hi everyone... I'm learning arrays and cant figure out why my cout is showing "scattered" output... I'll upload my infile and source code.

I'll also upload the example of the correct output my teacher wants us to show on execution.

I'm struggling with the "UNKNOWN" State Name listing too. I tried taking that out of my program and just focus on "KNOWN" state names but my output still comes out "scattered".

ToySoldier 0 Newbie Poster

Here Is The Corrected Code

Thanks.. I was getting a real headache. Let me get back to it... clean it up with tabs and figure out the rest of it.

After this program, I'm gonna go back to easier examples and start again from the beginning over Thanksgiving break.

ToySoldier 0 Newbie Poster

First off, I would suggest adding some tab characters "\t" instead of explicitly adding all the white spaces in. It makes your code really hard to read like it is.

At first I didnt know what you ment but I looked up \t's in my book. AWESOME... I did ask my teacher for an easier way besides spaces but he said for me to just use spaces. I'll surprise him with this program with tabs.

ToySoldier 0 Newbie Poster

could it be that infile and outfile are not defined? It would help if you posted the compile errors.

outfile.open("report.txt");
infile.open("people3.txt");

I think that was part of my problem. Thanks... let me get back to it and figure the rest out. I wish I had taken better notes on arrays :o

ToySoldier 0 Newbie Poster

Need help in finishing this problem. I was doign ok at first but somehow ran into 2 compile errors. Now I'm tired and going in circles. I need a fresh pair of eyes to look it over. This is my first time doing arrays.

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;



int main()

string first, last, code, name;
int number;
outfile.open("report.txt");
infile.open("people3.txt");

{string state_codes 
[10]={"AL","CA","FL","GA","IA","KS","MO","MI","MS","NM",};

string state_names 
[10]={"ALABAMA","CALIFORNIA","FLORIDA","GEORGIA","IOWA","KANSAS","MISSOURI","MICHIGAN","MISSISSIPPI","NEW 
MEXICO"};

cout<<"                                  PEOPLE REPORT"<<endl;

cout<<"                                    FALL 2006"<<endl;

cout<<"FIRST "<<"       LAST "<<"         SS "<<"          STATE "<<"         

STATE"<<endl;

cout<<"NAME  "<<"       NAME "<<"       NUMBER"<<"         CODE  "<<"         

NAME"<<endl;

outfile<<"                                PEOPLE REPORT"<<endl;

outfile<<"                                  FALL 2006"<<endl;

outfile<<"FIRST "<<"        LAST "<<"         SS "<<"          STATE 

"<<"         STATE"<<endl;

outfile<<"NAME  "<<"        NAME "<<"       NUMBER"<<"         CODE 

"<<"          NAME"<<endl;
 
for(i = 0; i<16; i++)
 {cout <<left <<setw(2) <<state_codes[i] << " "
       <<setw(15) << state_names[i] << endl;
 }
 return 0;
}

My output should look something like this... any help with finding my 2 compile errors would be appreciated.

PEOPLE REPORT
                         FALL 2005
 
FIRST     LAST             SS               STATE        STATE
NAME      NAME           NUMBER             CODE         NAME
 
JOE       JONES          123-45-6789        NM          NEW MEXICO
BOB       SMITH          111-11-1111        AL          ALABAMA
JOHN      DOE            999-12-1234        AA          UNKNOWN
JEB       BUSH           111-11-1112        FL          FLORIDA
JIMMY     CARTER         222-22-2222        GA          GEORGIA
JANE      DOE            999-22-1111        ZZ          UNKNOWN
ROBERT    WHEATFIELD     888-88-0000        KS          KANSAS
JUNE      HAYSEED        222-22-3456        IA          IOWA
ARNOLD    SWARTZ         678-88-1111        CA          CALIFORNIA
HENRY     FORD           121-21-2121        MI          MICHIGAN
VIDA      BLUE           234-00-1111        CA          CALIFORNIA
JOHN      WAYNE          666-66-0000        CA          CALIFORNIA
WILLIAM   SWAMPRAT       555-55-0987        MS          MISSISSIPPI
MATTHEW   BLUNT          777-00-1111        MO          MISSOURI
DANIEL    BOONE          111-99-0000        MO          MISSOURI
ZEB       WASHINGTON …
ToySoldier 0 Newbie Poster

Okay... I went to bed after trying to figure it out. I thought I might be tired or something... I'll post back and let u know how it turned out. Thanks...

ToySoldier 0 Newbie Poster

I'm trying that but all the "Project" options are ghosted out... why make this program so difficult ??? "AAaggghhhh !!!"

It comes with my SAMS "Teach yourself C++ in 24 hours" book. I followed the steps in the book and I get the same result.

<edit> I opened up an existing project within the program... it's working for now... I will post back if I run into some problems.. <sigh>

Still annoying... that I cant figure out how to start a "fresh" project

ToySoldier 0 Newbie Poster

I can compile my programs easily using MS C++ but I just installed Borland C++BuilderX and I cant compile... <sigh> It's ghosted out.

// my program
#include <iostream>

int main()
{
std::cout << "Hello World!\n";
return 0;
}

This is what I'm doing...

1: Execute C++BuilderX
2: Click new
3: Click Source File
4: Click New C file
5: I type in above Hello World program

I go to Make Project and everything is ghosted..... wont let me compile <sigh>

Anyone know what I'm doing wrong ?

ToySoldier 0 Newbie Poster

Hi... thru trial & error.. I managed to get my homework program to compile. However I'm pretty sure I did it the long way :-| .

Okay..I managed to figure it out. I wasnt in class when he handed us a Text file... made my program MUCH easier to do...

ToySoldier 0 Newbie Poster

Hi... thru trial & error.. I managed to get my homework program to compile. However I'm pretty sure I did it the long way :-| . Can someone give me a direction to make it easier? Brand new to C++ so bear with me. I have enough to make the teacher happy but I'm not. I copy and pasted my source code directly from Visual C++ 6.0:

How do I get my output to print on my printer? All I see is a "DOS" type screen popup which does not give me an option to print it. I suppose I could ask my teacher tomorrow but it would be great if I didnt have to.

// Assignment #1 due 4 Oct 2005
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;

const double taxes = 1.05; // Sales Tax 5%

const string c1="BREAKFAST-CAFE ",c2="SALADS-ARE-US",c3="WRONG-WAY-INC", // Customer Names
c4="BUGS-BUNNY",c5="HAWAII-50",c6="HAPPY-HOUR-BAR",c7="CAMPELL-SOUP",
c8="CACTUS-JACK",c9="HEALTH-FOODS",c10="NO-WAY-TODAY",
c11="DOCTORS-AWAY",c12="DAN-TUCKER",c13="LAST-CHANCE"; // Customer Names

const string in1="ORANGES",in2="LETTUCE",in3="TURNIPS",in4="CARROTS",in5="PINEAPLES", // Item Names
in6="LIMES",in7="TOMATOES",in8="BEANS",in9="MELONS",in10="OKRA",in11="APPLES",in12="SQUASH",in13="ORANGES";

const int no1=100,no2=100,no3=99,no4=10,no5=125,no6=100,no7=750,no8=50,no9=100, // Number Ordered
no10=99,no11=900,no12=10,no13=100;

const double ip1=10.25,ip2=9.50,ip3=1.00,ip4=6.00,ip5=25.00,ip6=2.00,ip7=5.00, //Item Price
ip8=4.00,ip9=5.10,ip10=2.00,ip11=6.15,ip12=1.55,ip13=10.00;


int main()
{
    cout << left << setw(17) << "Customer Name" << left << setw(17) << "Item Purchased" << left << setw(10) // Names of Columns
        << "Subtotal" << left << setw(10) << "TOTAL w/Tax"
        << endl << endl; 

    cout << fixed << showpoint << setprecision(2); //print money fields to 2 places. Force Zero's and Decimal

    cout << left << setw(17) << c1 << left << setw(17) << in1 << left << …