C++ Help please . .

Soldato
Joined
14 Apr 2004
Posts
11,888
Location
UK
Hey guys, i'm making a 'pacman' style game for my uni assignment. I passed and successfully created a decent game a while back but I failed the exam so I have to do refferal work. Now the problem is, I can't rip my previous work, I have to use the structure we're given.

Now I've been stumped for a few hours and I can't work it out :(

I've deleted a fair amount of code but here's what I have so far:

PHP:
.

All I want is the sweet to appear, I can figure out the rest.
 
Last edited:
Be more specific about your problem and you may get a better response, I'm happy to help but after a days work I can't really be bothered to trace someones code. Point us to where your problem is.
 
You should properly brace things such as your if statements. In the last function you should brace the line you want included in the if statement as its not indented as it should be. Also its good practise to place the integer first in comparison statements such as if ( 8 == something) as then if you forget an =, the compiler will throw an error. If however you say if (something = 8) the compiler will not complain as you are telling it to assign something. Easy method to remove difficult to trace bugs.
 
Hi there, sorry I should have been more specific.

I've managed to overcome a few issues however I'm experiencing a very strange problem.

Basically I sent my code to a friend and it worked for him in VS 05. I compiled my program using remote desktop on Uni's server using C++ 6, now when I compiled the application it fired up but when I had pressed a key, the program keeps crashing (debugging).

Now I've just installed VS and I get the following error:

1>d:\software engineering\fundementals of programming\visual studio 2005\projects\assigment 2 re-work\assigment 2\assigment 2\assigment 2.cpp(169) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

Yes, stdafx.h is in the header and source. I'd really appreciate it if someone could help as I can't finish program till this is solved and I only have 2 days remaining :(
 
You only need to # include it in the cpp file. Can you post your cpp file here please. Have you tried cleaning the solution and then rebuilding as the pch file may have been corrupted or something causing that error.
 
Last edited:
Ladforce said:
You only need to # include it in the cpp file. Can you post your cpp file here please. Have you tried cleaning the solution and then rebuilding as the pch file may have been corrupted or something causing that error.
Right it seems that problem is gone. It doesn't want to include my libraries it seems:



Feel free to add me to msn :)
 
So at the top of your Assignment2.cpp you have a #include for each of the 4 header files? And your still getting identifier not found?
 
Ladforce said:
So at the top of your Assignment2.cpp you have a #include for each of the 4 header files? And your still getting identifier not found?
Indeed, I have the following:

PHP:
//---------------------------------


#include <iostream>         //for output and input: getch() & cout << 
#include <conio.h>           //for kbhit 
#include <iomanip>           //for formatted output in 'cout' 
#include <fstream>           //for files 
#include <string>            //for string 
#include "RandomUtils.h"     //for Seed, Random, 
#include "ConsoleUtils.h"    //for Clrscr, Gotoxy, etc.
#include "stdafx.h"
using namespace std;


//---------------------------------
 
There is no include for TimeUtils.h but I assume those functions are not found in that header? Also, why are your function prototypes inside main()?
 
Ladforce said:
There is no include for TimeUtils.h but I assume those functions are not found in that header? Also, why are your function prototypes inside main()?
I've had no use for TimeUtils.h, I shall delete that.

That's the structure of the program that I have to follow as per specification.

I suspect that it's not including even the basics such iostream etc :\

Have I stored it in the correct directory?
 
yea you have, it would complain about file not found otherwise. could you check in project->properties->configuration properties->common language runtime support and see what yours is? Also try renaming getch() to _getch() as I believe it changed name recently (maybe in vs2005).
 
Last edited:
try #include "stdafx.h" before any other header is included at the top of the .cpp file. seems like something stupid in the include order is screwing it.
 
Ladforce said:
try #include "stdafx.h" before any other header is included at the top of the .cpp file. seems like something stupid in the include order is screwing it.
That gave me 16 errors as opposed to 9 but every message is the same:

1>d:\software engineering\fundementals of programming\visual studio 2005\projects\assigment 2 re-work\assigment 2\assigment 2\consoleutils.h(56) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 
go to project->properties->configuration properties->c/c++->command line and add /wd 4430 in the additional section. try building again.
 
I'd also like to add, when I connect to remote desktop at uni, when it crashes and then debugs the yellow arrow points at the last line of the following function:

PHP:
void placeSweetsOnGrid ( char grid[][SIZEX+1], int sweets[][2])

{ 
		for ( int swno(1); swno <= NUMSWEETS; ++swno) //for each sweet
		{ 
			int dy = sweets[swno][0]; 
			int dx = sweets[swno][1]; 
			if (! (( dy == 0) && (dx == 0)))
			grid[dy][dx] = SWEET;
		} 
}
Which is strange as it's valid.
 
its not included in the if statement as its not indented. you should encapsulate anything you want in if statements in braces to prevent ambiguity. see if that helps.
 
Back
Top Bottom