CoolGamer48 65 Posting Pro in Training

You don't even need Direct3D - the Windows API has your back:
link

CoolGamer48 65 Posting Pro in Training

Post the header file and the .cpp file. There's no specific special thing you need to do to create a header file. What you said could be correct, but it's a bit vague.

CoolGamer48 65 Posting Pro in Training

People have already done the work for you. The Direct3D extensions library (d3dx) has functions for loading bitmaps into Direct3D surfaces or textures. Unless you want to manually load the bitmap into your program as a learning experience, or if you just feel better doing things yourself, use Direct3D (or OpenGL if you're an open source kind of guy).

CoolGamer48 65 Posting Pro in Training

Thank you!
But, tell me please, in the first method why the blank character (the space) is omited by default?
Is there one error, or such work the method?

The extraction operator >> skips over whitespace. To read a file character by character including whitespace, use the get() method. Though I would just listen to Ancient Dragon.

CoolGamer48 65 Posting Pro in Training

It means that strncpy is old and/or something better is around to use instead of it.

CoolGamer48 65 Posting Pro in Training

Err... not exactly sure what you were talking about with the source and destination stuff, but this:

operator int()
{
return r*r-i*i ; // some conversion to int
}

is what I was looking for. Thanks.

CoolGamer48 65 Posting Pro in Training

Hmm, perhaps you could do:

int x;
	x = *(new int[5]);
	(&x)[0] = 1;
	(&x)[1] = 1337;

but I believe this is a very bad idea. new is creating an array of five ints, and this array is being copied into x, leaving the original array somewhere in memory that is unknown to us, so we can't delete it later. Also, x only has room for one int, not 5, so copying 5 ints into x may intrude on memory belonging to someone else.

CoolGamer48 65 Posting Pro in Training

To my understanding, certain classes, like ifstream, have a conversion to a primitive data type, like bool. In other words, you can do this:

if((fin >> x) && done == false)
//...

Now, does this simply work because ifstream has the && operator overloaded, or can objects of that class just always be converted to bool? So would this:

if((fin >> x))
//...

work? If so, how can you set a class to convert to bool, or int, or any other data type?

CoolGamer48 65 Posting Pro in Training

For the same reason that doing p++ advances by one unit of whatever the pointer is pointing to, not by 1 byte of memory.

Oh, ok...

CoolGamer48 65 Posting Pro in Training

> Develop a program in C++
Is that an order?

Are you not supposed to know Latin to find that funny?

CoolGamer48 65 Posting Pro in Training

The address of a variable returned by the reference operator (&) is not an l-value, meaning you can't put it on the left side of an assignment operator. Besides, why would you want to?

CoolGamer48 65 Posting Pro in Training

Why DirectX instead of OpenGL? Personally I use DirectX, but even if you don't mind DirectX being closed-source and platform-specific, you may still choose to use OpenGL.

CoolGamer48 65 Posting Pro in Training

I ran this for fun.

Is it necessary to cast the addresses as ints before subtracting? I printed both addresses, and saw that they were 4 apart, but &x[1] - &x[0] came out as 1. But when I cast them to ints, it was 4. Why is the cast necessary?

CoolGamer48 65 Posting Pro in Training

Alright, thanks.

CoolGamer48 65 Posting Pro in Training

I don't know which awesome games you saw at the apple store (especially because apple isn't too well known for games), but even if you were using C++, you would not be able to create a game like Empire at War on your own. My guess is 20-30 programmers alone worked on Empire at War, and when you bring sound people, game designers, 3D artists, testers, etc. into the mix, I'm guessing the count will be around 100.

I'm not familiar with Cocoa, so I don't know whether it would be possible to program a game of the likes of Empire at War with it, but I'm just saying that that's likely the least of your worries.

CoolGamer48 65 Posting Pro in Training

Say I have a file file1.h:

namespace a
{
     int Func()
    {
        return 5;
    }
}

and a file file2.h

#include "file1.h"

namespace a
{
    class Foo
    {
        Foo();
    };
}

and file2.cpp:

#include "file2.h"

a::Foo::Foo()
{
    Func();//<----
}

Can Func() be referenced like this, or do we need to do a::Func()?

CoolGamer48 65 Posting Pro in Training

Man, I realise that you could solve the problem right away, I know you guys are experienced and these problems are too easy for you. I just wanted to help the dude like some of you guys helped me. And now that he's got the solution, he can look at it, and get new ideas and maybe surprise his teacher, who knows :)

Or he could submit it as his homework without giving it a second glance. By making him give us some code first or at least ask a specific question, we know that he's tried on his own first, and by only giving pieces of the answer, we know that he's doing some (and hopefully most) of the work.

CoolGamer48 65 Posting Pro in Training

Depending on your needs, you may also consider lists or deques.

Here's a reference for all STL containers: link

CoolGamer48 65 Posting Pro in Training

A cast isn't necessary. To my knowledge, all four of the example I gave are valid. I was wondering if any one of them is considered better than another for style purposes, or if there even is a unanimous (or unanimous-ish) agreement on which is better.

CoolGamer48 65 Posting Pro in Training

In regard to good style, is it better to use the NULL macro, or should you just use 0? And should you cast either one to the type of pointer you're using?

i.e.:

int* pInt = (int*)0;//this,
int* pInt2 = 0;//this,
int* pInt3 = (int*)NULL;//this,
int* pInt4 = NULL;//or this?
CoolGamer48 65 Posting Pro in Training

I tried everything and none of them worked on my friend's computers. :( Most commonly they said to download Visual C++ 2008 Redistributable package, but I'm using Visual C++ 2008 Express. Any suggestions?

It doesn't matter if you're using Express. I had to do the same thing.

CoolGamer48 65 Posting Pro in Training

If you're under Windows, you don't need anything.
The Win32 api does it automatically.

The Win32 api can convert .bmp fonts into .ttf file?

CoolGamer48 65 Posting Pro in Training

Thanks. A lot of it went over my head, but it's a nice resource to have.

CoolGamer48 65 Posting Pro in Training

I myself have run into problems with side by side configuration, and while I don't fully understand it, it is not an issue with Vista. I've run into the same problem when moving an app from one xp machine to another.

CoolGamer48 65 Posting Pro in Training

A friend of mine recently asked me how one would convert a .bmp font to a .ttf. I said I was unsure, but it got me thinking to how I would code a program to do that. How would someone who wants to create a .bmp to .ttf converter go about it? Is there some sort of documentation somewhere explaining how the .ttf file format works? And in addition to that, what about other file formats? Where do the people who code programs that create .jpegs or play .mp3s learn about how to properly read/write from those file formats? Is the information publicly available by somewhere?

VernonDozier commented: Excellent question, and one I'd like to know the answer of too. I'll be watching this thread! +5
CoolGamer48 65 Posting Pro in Training

Have you compiled and run this?

This:

avgNoOfGuesses=sum/noofgamesplayed;

seems like it would generate an error, since noofgamesplayed is 0, and you're dividing by it. Besides, that statement and the one above it are unnecessary.

Do you need to write the functions, or do you simply need to call them? Either way, the functions seems to have a betting system that your current game doesn't implement.

CoolGamer48 65 Posting Pro in Training
cout << " \n"; 
char letter;	

cout << "Enter a letter to end the program:\n";
cin >> letter;
cout << "Goodbye.\n"; 
return 0;
}

I know this probably isn't going to be much help to you, but it's way easier and simpler to, instead of having to type a random letter and press enter, you can either use:

system("pause");

This will print the line, 'Press any key to continue...', so the user doesn't have to press enter.

And by using

#include <conio.h>

and, for example,

cout << "Press any key to do something";
_getch();

That allows you to enter your own custom message to the user, before instantly exiting the program on the key press.

cin.get() works. it doesn't disrupt the program like system("PAUSE"); and you only need to #include <iostream>

CoolGamer48 65 Posting Pro in Training

C++ arrays are static in size, yes, but the Standard Template Library has containers that can do what you want. lists sounds like they may fit your needs, but vectors or deques may also be of use.

As far as this:

CStringArray MyArray[numData]

You need to use dynamic memory to allocate an array to a size unknown at compile-time. Like this:

CStringArray* MyArray;
MyArray = new CStringArray[numData];
//use the array
delete[] MyArray;

If this is all you need, you can ignore the stuff about the STL (standard template library). But if you want it to grow and shrink during runtime, you'll need a list or another container.

CoolGamer48 65 Posting Pro in Training

pointers and arrays and similar

link
scroll down around half-way to the section called "Pointers and arrays"

CoolGamer48 65 Posting Pro in Training
int converter(int x, int y)
{
    if(y == 0)
        return 0;//or -1, or whatever you want to happen instead of a divide by zero	
    return x / y;
}

You could use backspace to get rid of the old text:

for(int i = 0;i < numChars;i++)
    cout << "\b";

numChars is the number of characters you output.

There's a clear command on the Linux kernel that clears the prompt of text. I don't know if there's a Windows equivalent, but you could call it with system();

CoolGamer48 65 Posting Pro in Training

You might want to also add a check in converter() (or somewhere else) to make sure that the number of deaths is not 0.

CoolGamer48 65 Posting Pro in Training

It isn't bogus crap. Learn to understand it and you'll begin to be able to solve problems on your own, though its understandable that at first you'll have no idea what it means.

The compilers complaining that the function PlaySound is declared somewhere, but it has no implementation. I'm actually not sure why it said it twice. The implementation would either be in the form of a .cpp file, or, in this case, a .lib file.

To fix this you need to link to the .lib winmm.lib. A simple way to do this is to add

#pragma comment(lib,"winmm.lib")

in one of your source files.

Wiki_Tiki commented: Helped well with 2 fatal compiler errors +1
CoolGamer48 65 Posting Pro in Training

scratch this - didn't see the second page

btw, how do you get the code tag to come up properly without it thinking it's an actual code tag?

CoolGamer48 65 Posting Pro in Training

Just so you know, the typedefs aren't necessary to do what you want... they just make it much easier. You had the right idea on your own. If this vector<string> is a 1D vector, and this vector<vector<string>> is a 2D vector, then following the pattern, you should've been able to to come up with this: vector<vector<vector<string>>> as a 3D vector.

CoolGamer48 65 Posting Pro in Training

It has to do with the way your compiler is interpreting strings (I think it happens when you set the character encoding to unicode instead of multibyte, or something like that).

I think that this:

PlaySound((LPCWSTR)"beep.wav", 0, SND_LOOP|SND_ASYNC);

will work.

CoolGamer48 65 Posting Pro in Training

Salem meant you should wrap your code in code tags (the (code) button on the top, or just type YOUR CODE HERE, with four spaces before code).

Do you want the for loop to be part of this conditional:

else if ((peso > 30) && (peso < 1000) && (dia = 9))
cout << " Se le cobraran 15$ " << "\n";
//for loop only executed if peso is between 30 and 1000 and dia is 9

If so, just wrap the code in curly brackets:

else if ((peso > 30) && (peso < 1000) && (dia = 9))
{
    cout << " Se le cobraran 15$ " << "\n";
    for(;;)
    //your loop here
}
//next else if condition

If you meant that the loop is executed regardless of the above conditional, you can also do that, though the else if after it would need to become a regular if:

/*else*/if((peso > 1000) && (dia = 7))
CoolGamer48 65 Posting Pro in Training

Interesting... I never realized you could add on the the overloaded operators of cin and cout.

CoolGamer48 65 Posting Pro in Training

You can make the code shorter by eliminating the curly brackets for if statements with only one line.

So this:

if (user_selection == "Pizza")
                {
                        eChoice = Pizza;
                }
                else if (user_selection == "Lasagna")
                {
                        eChoice = Lasagna;
                }
                else if (user_selection == "Chips")
                {
                        eChoice = Chips;
                }
                else
                //...

could become:

if (user_selection == "Pizza")
                        eChoice = Pizza;
                else if (user_selection == "Lasagna")
                        eChoice = Lasagna;
                else if (user_selection == "Chips")
                        eChoice = Chips;
                else
                //...

Just to be clear you're assuming user_selection is some kind of string-container (hopefully an std::string), because in the OP is was of type food.

CoolGamer48 65 Posting Pro in Training

don't use char arrays or char*. use std::strings. if your input is a string, you can just use the [] operator to access elements in it (it's been overloaded)

string str = "Hello";
if(str[1] == 'e')
//this is true

If you really want to know how to convert a string to an array:

char strarray[100];
string str = "Hello";
for(int i = 0;i < str.length();i++)
    strarray[i] = str[i];

but this is useless given that the [] operator can be used with strings.

CoolGamer48 65 Posting Pro in Training

I type in Pizza.

That won't work. The symbol Pizza is only defined in your program to mean 10. When you type in "Pizza" at the console, it's interpreting it as a char* (I think), and I don't know how that translates to an integral type, but it won't be 10. You need to actually type in the number 10, or interpret the string "Pizza" and realize that it means 10.

CoolGamer48 65 Posting Pro in Training

When you run the program, and you want to guess that your favorite food is pizza, do actually type in "pizza", or do you input 10?

CoolGamer48 65 Posting Pro in Training

How did you store the first object? Repeating that should do it....

CoolGamer48 65 Posting Pro in Training

Post your errors, but at a glance:

void Mainmenu();
{
     string choice //missing semicolon
     //....
CoolGamer48 65 Posting Pro in Training

To address your first issue: void pointers. Google it. It's basically a pointer that has no type bound to it. I haven't used them too much but I think they fit your needs.

Your second problem:
You can check to see if there is data to be read. Use the empty() method of the vector class to see if it is empty or not. As for arrays, if you initialize the array of pointers to NULL, rather than having bad pointers. Then you can do

if(passengers[i])
//output data
CoolGamer48 65 Posting Pro in Training

You need some basic knowledge of the Windows API to use DirectX - so either way you should check this out: http://winprog.org/tutorial/simple_window.html.

Buying books is a very good idea. I haven't read any books on the Windows API. A book on DirectX I did read was Beginning Game Programming, by John S. Harbour. It begins with some of the Windows API, but its mostly DirectX focused. I can't say I was extremely thrilled with it - I ran into some problems with DirectSound. But it was pretty good for most of the other things. FYI, it uses C, not C++, but I didn't mind. It gave me practice converting the C code into C++.

As for what to use, what types of programs do you intend on making? If you want to make games, or perhaps apps with your own style GUI - use DirectX. If you want to make non-game programs that look like Windows programs, use the Windows API.

CoolGamer48 65 Posting Pro in Training

Google is very nice:
link

As others have said, post code, but this, or something like it, would cause the problem you're having:

void Func()
{
    cout << "I am a function.\n";
}

int main()
{
    if(Func())//Func() returns nothing - you can't check if a nonexistent result is true or false
        cout << "Helllo.\n";

    return 0;
}
CoolGamer48 65 Posting Pro in Training

C++ is a language, as defined by ISO.
Visual C++ is an implementation (like Borland, GNU, Intel).

Any modern 32-bit compiler will probably meet your needs for learning C++.

Wait, so every compiler is considered to have it's own "implementation" of C++? So, is it possible to have a compiler that compiles pure C++, or is pure C++ just a language on paper?

Or did you just mean that Visual C++ implements the C++ language?

CoolGamer48 65 Posting Pro in Training

Is it bad to make a reference parameter optional by giving it a default value? Like here:

int Parse(std::string filename, std::string& error = (std::string)"");

Here, the caller of the function may pass an optional std::string that will be filled with an error message if there is one. Is this considered "ok", both as far as being safe, good code and having good style?

CoolGamer48 65 Posting Pro in Training

scratch this

CoolGamer48 65 Posting Pro in Training

exp *= exp when exp is 1 means exp *= 1; , exp = exp*1; , exp = exp; . That increment does nothing. To increase exp by 1 every iteration, do exp += 1; , if that's what you meant. Also, what is exponente? What is it set to?