Announcement: Be excellent to each other.


Caravel Forum : Other Boards : Anything : C++
New Topic New Poll Post Reply
Poster Message
vinheim
Level: Smiter
Rank Points: 300
Registered: 05-31-2007
IP: Logged
icon C++ (0)  
So I got myself a book on C++ and started studying it and downloaded visual c++.
First of, I don't know how to create the .exe
I started by making an empty project and creating a .cpp file under resource files. Compiling and building it won't create an .exe like it says it should on the internet, instead it creates an application.
Second, searching on google didnt help, is there any online tutorials someone could show me on creating simple games on c++?
04-28-2008 at 01:53 AM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
brian_s
Level: Smitemaster
Avatar
Rank Points: 587
Registered: 05-27-2004
IP: Logged
icon Re: C++ (+1)  
I guess at some point you will need to learn about the Windows API (unless you are on a Mac). http://www.winprog.org/tutorial/ is for plain C, but the focus on the basic nuts and bolts of the API are also useful in C++. I managed to learn the basics of windows programming in C just from that site.

Also, http://msdn.microsoft.com/library/ is Microsoft's official online Windows API reference.
04-28-2008 at 03:26 AM
View Profile Send Private Message to User Send Email to User Show all user's posts This architect's holds Quote Reply
aztcg7
Level: Master Delver
Avatar
Rank Points: 104
Registered: 03-08-2005
IP: Logged
icon Re: C++ (0)  
Compared to the Windows API, SDL is much simpler overall to learn, and is capable of being compiled and run on all of the major operating systems today.

http://forum.caravelgames.com/viewtopic.php?TopicID=17466 has some good discussion on SDL.

You might also want to try http://lazyfoo.net/SDL_tutorials/index.php as it has some really good code on basic SDL things having to do specifically with games. Be sure to read the articles, as they have alot of good info in them you can't really get elsewhere.

____________________________
In other news, :( is a considerably more stylish way to express sarcasm than ;), because everybody uses ;) and I am /indie/. INDIE, I TELL YOU.
04-28-2008 at 06:07 AM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
eb0ny
Level: Smiter
Avatar
Rank Points: 484
Registered: 09-12-2007
IP: Logged
icon Re: C++ (0)  
IMHO you are trying to do too much too fast. First learn the language, write some simple programs and then move on to graphical programming.

I can't give you any advice on any graphical libraries, but for "pure" C++ stuff try this post. Hope it helps.

____________________________
Click here to view the secret text


[Last edited by eb0ny at 04-28-2008 06:55 AM]
04-28-2008 at 06:55 AM
View Profile Send Private Message to User Show all user's posts This architect's holds Quote Reply
Ravon
Level: Master Delver
Avatar
Rank Points: 220
Registered: 02-19-2004
IP: Logged
icon Re: C++ (0)  
I think everyone misinterpreted what vinheim is asking. He's not asking for instructions on SDL or the windows API. He's just asking why his program won't compile to an executable using Visual C++.

My advice would be to download dev-c++. It is a very good IDE for windows, especially for small projects. I had great success with it when I was learning to code.
04-28-2008 at 05:58 PM
View Profile Send Private Message to User Send Email to User Show all user's posts This architect's holds Quote Reply
Briareos
Level: Smitemaster
Avatar
Rank Points: 3516
Registered: 08-07-2005
IP: Logged
icon Re: C++ (+1)  
But... but... a file with the extension "exe" IS a Windows application.

It's just that Windows Exploder dain bramagely is set up to hide file extensions by default; open the file's properties and you'll see it's extension really is "exe"...

np: Justus Köhncke - Feuerland (Safe And Sound)

____________________________
"I'm not anti-anything, I'm anti-everything, it fits better." - Sole
R.I.P. Robert Feldhoff (1962-2009) :(
04-28-2008 at 06:31 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
eb0ny
Level: Smiter
Avatar
Rank Points: 484
Registered: 09-12-2007
IP: Logged
icon Re: C++ (+2)  
Addition to the last post: how to make file extensions visible.

1) Go to Control Panel.
2) Switch to Classic View (on the left, at the top).
3) Open Folder Options.
4) Select View tab.
5) Uncheck "Hide extensions for known filetypes".
6) Hit OK.

After that you should see your exe file. Speaking of which, if you have created a new Visual C++ project, then the executable is kind of hidden, because this IDE uses a specific folder structure.

For example, if you have project "x", then it's files are located in ../x/x. The first x is the solution folder (a solution simply groups projects and takes the name of the project by default), where the project resides (which the second x).

Now, the compiler stores the executables in the folders, whose names are build settings' names. By default the compiler uses "debug" build settings (i.e. the program is optimized for debugging). So, what you have to do is look for x.exe (x = project name, once again) in ..x/debug or ..x/x/debug folders.

If you coded your source files without creating projects, then the executables are placed in the same folder and the sources.

Long story short, scan your folders.

____________________________
Click here to view the secret text

04-28-2008 at 07:20 PM
View Profile Send Private Message to User Show all user's posts This architect's holds Quote Reply
coppro
Level: Smitemaster
Rank Points: 1308
Registered: 11-24-2005
IP: Logged
icon Re: C++ (0)  
If you want my honest advice for learning C++, my best recommendation would be to drop the IDE altogether and use the command line. If you my super-honest advice, use KATE (the KDE Editor, currently works on Linux, though they are working on a Windows version). KATE has great syntax highlighting and a built-in terminal, without all the massive bloat contained in an IDE. IDEs make it really difficult to actually learn how to program because they try and impose their reality on you because of the work they take to set up.

Also, what book are you using? Like all topics, C++ books range from awful to excellent. It makes worlds of difference whether or not you have a decent material. And personally, I'm of the opinion that most C++ texts do it all wrong - they introduce pointers before the std::string class. Why I don't know - you're trying to teach people, not beat them over the head with concepts that are difficult to grasp.
04-29-2008 at 03:20 AM
View Profile Show all user's posts Quote Reply
vinheim
Level: Smiter
Rank Points: 300
Registered: 05-31-2007
IP: Logged
icon Re: C++ (+1)  
Ok, here are the chapters in my book, I've made all the projects at the end of each one up to chapter 6 successfully and understand them quite well:
Click here to view the secret text

I'm not gonna make games early, but if I did, what chapter should I go up to? (I'm still gonna read everything)

EDIT: Coppro, the book is Absolute C++ Programming by Walter Savitch and it works well! I got it 'coz it said the guy was from Disneyland or Walt Disney or California or something

[Last edited by vinheim at 04-29-2008 12:26 PM]
04-29-2008 at 12:21 PM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
Briareos
Level: Smitemaster
Avatar
Rank Points: 3516
Registered: 08-07-2005
IP: Logged
icon Re: C++ (0)  
vinheim wrote:
I'm not gonna make games early, but if I did, what chapter should I go up to? (I'm still gonna read everything)
Ummm... in that case you might want to first figure out what kind of game (2D, 3D, action, strategy, stepping, etc.) it's gonna be, then choose some libraries (if you look at your TOC closely you'll find that things like graphics, audio et al are totally absent, as that's all handled by libraries and not C++ itself) and algorithms you're gonna need (or need to think up yourself) and finally get books (or perhaps electronic documentation/tutorials) on those...

np: Balil - Choke and Fly (Trainer (Disc 2))

____________________________
"I'm not anti-anything, I'm anti-everything, it fits better." - Sole
R.I.P. Robert Feldhoff (1962-2009) :(
04-29-2008 at 01:47 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
vinheim
Level: Smiter
Rank Points: 300
Registered: 05-31-2007
IP: Logged
icon Re: C++ (0)  
Here's the code for my first program, I've redone it and have run across a problem where if you enter more than one letter or number when it says "try again" it repeats try again for the number of letters or digits. Can someone explain why and also how to fix it
#include <iostream>
#include <cmath>
using namespace std;

//This asks the user how much does a cereal package weigh in ounces
//It then converts it into metric tons, and tells you how much cereal is enough for a metric ton
//It lets the user do this many times as long as s/he enters y (for yes) after try again
int main()
{
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);

	const double rate = 35273.92;
	double input, output;
	char ans;

	do
	{
	    do
	    {
		    cout << "Enter weight of cereal package in ounces: ";
	        cin >> input;
		} while (input <= 0);

		output = input/rate;

		if (output < 0.01)
			cout << "This is less than 0.01 metric tons\n"
		         << "You need " << static_cast<int>(ceil(1/output)) << " box for a metric ton\n";
		else if (output == 1)
			cout << "This is the same as 1 metric ton\n"
		         << "One box is enough for a metric ton\n";
		else
			cout << "This is the same as " << output << " metric tons\n"
			     << "One box is enough for a metric ton\n";
		
		do
		{
			cout << "Try again?(y/n) ";
		    cin >> ans;
		} while ((ans != 'y') && (ans != 'n'));

	} while (ans == 'y');

	cout << "End of program";

	return 0;
}


EDIT: And also anyway to clean it up or make it simpler?

[Last edited by vinheim at 04-29-2008 02:39 PM]
04-29-2008 at 02:27 PM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
Briareos
Level: Smitemaster
Avatar
Rank Points: 3516
Registered: 08-07-2005
IP: Logged
icon Re: C++ (0)  
vinheim wrote:
[I] have run across a problem where if you enter more than one letter or number when it says "try again" it repeats try again for the number of letters or digits. Can someone explain why and also how to fix it[?]
The variable "ans" you're using to read the user's input is a char variable, which means it can only store a single character and so only a single character is read from cin, which is then checked whether it's 'y' or 'n', and if it is neither the loop will be run again, reading just another single character from standard input.

However, if you use a string instead of a single character it should read everything you have typed at once - of course then you'll also might have to compare it with "y" and "n", i.e. strings instead of characters.

np: Dead Letters Spell Out Dead Words - Lament (Bonus Track) (45Tribute)

____________________________
"I'm not anti-anything, I'm anti-everything, it fits better." - Sole
R.I.P. Robert Feldhoff (1962-2009) :(
04-29-2008 at 04:17 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
eb0ny
Level: Smiter
Avatar
Rank Points: 484
Registered: 09-12-2007
IP: Logged
icon Re: C++ (+1)  
Ugh. C++ stream flags. That's why I still use printf() for debug output (and any other output, for that matter).

One more thing: never ever EVER compare floating point variables with == operator. Floating point variables are notorious for their inaccuracy (for example, sqrt(10000.0) might return 99.99999). If you really have to compare them, try to use something like this:
const double EPSILON = 0.000001;    // Depends on accuracy you need

bool compareFloats(double d1, double d2)
{
    double diff = fabs(d1 - d2);    // Takes modulo of difference
    return (diff < EPSILON);        // Returns, whether two floats are even within defined bounds
}


____________________________
Click here to view the secret text


[Last edited by eb0ny at 04-29-2008 06:19 PM]
04-29-2008 at 06:17 PM
View Profile Send Private Message to User Show all user's posts This architect's holds Quote Reply
Briareos
Level: Smitemaster
Avatar
Rank Points: 3516
Registered: 08-07-2005
IP: Logged
icon Re: C++ (+1)  
eb0ny wrote:
const double EPSILON = 0.000001;    // Depends on accuracy you need

bool compareFloats(double d1, double d2)
{
    double diff = fabs(d1 - d2);    // Takes absolute value of difference
    return (diff < EPSILON);        // Returns, whether two floats are even within defined bounds
}
Comment fixed.

(It's "modulus", BTW, but using "absolute value" instead makes it unpossible to confuzzle it with "modulo" arithmetics, i.e. calculating the remainder of a division...)

____________________________
"I'm not anti-anything, I'm anti-everything, it fits better." - Sole
R.I.P. Robert Feldhoff (1962-2009) :(
04-29-2008 at 06:25 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
Mattcrampy
Level: Smitemaster
Avatar
Rank Points: 2388
Registered: 05-29-2003
IP: Logged
icon Re: C++ (0)  
coppro wrote:
If you want my honest advice for learning C++, my best recommendation would be to drop the IDE altogether and use the command line. If you my super-honest advice, use KATE (the KDE Editor, currently works on Linux, though they are working on a Windows version). KATE has great syntax highlighting and a built-in terminal, without all the massive bloat contained in an IDE. IDEs make it really difficult to actually learn how to program because they try and impose their reality on you because of the work they take to set up.

I'm not sure I agree with this: I find myself working much more efficiently in an IDE, and I find the discoverability of classes in something like Visual Studio very helpful. Without it, I probably wouldn't have become as familiar with the interfaces of the classes I'm using as I am.

But then I've got some choice words for the command line as well. I think visually, and so I find the mental hurdle of thinking in terms of names rarely worth the time spent moving the mouse around.

____________________________
What do you call an elephant at the North Pole?
Click here to view the secret text

05-01-2008 at 09:12 AM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
New Topic New Poll Post Reply
Caravel Forum : Other Boards : Anything : C++
Surf To:


Forum Rules:
Can I post a new topic? No
Can I reply? No
Can I read? Yes
HTML Enabled? No
UBBC Enabled? Yes
Words Filter Enable? No

Contact Us | CaravelGames.com

Powered by: tForum tForumHacks Edition b0.98.8
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team and the Caravel team.