#include?

Da_iMac_Daddy

Not-so-Neo-DumbA$$
OK so I'm using Borland C++ at school, we have all these libraries that aren't present on a mac, like lvp\random.h or string.h.

OK so this is what I need:
1. A whole word with cin?
2. A randomly generated number.
3.Any documentation on the libraries for PB and what they do.

Thanx in advance.
 
a whole word? thats for a little thing called character arrays :).

for a whole word, do this:

char word[10]; // it can store up to 10 characters.

cout << "Enter some stuff(limit 10):\n";
cin >> word;
cout << "\nHeres the stuff you put in:\n";
cout << word;

all you need is iostream for that :)

a random number? tis' a little function called rand(); i forgot how to lock the precision (aka a random # between x - y) but it has to do with modulus(%) or something like that. rand(); requires math.h, which project builder DOES have
:D
Borland? I think i use that one too in school...what school you go to? :)
 
You mention PB so I assume you have the developer package installed. For info on how to use PB: start PB and click on Help in the menu bar at the top of the screen. There's a list of help topics including PB as well as the various platforms.

As you apparently know, Cocoa is Objective-C programming. Carbon supports C/C++.

If you want to look at the documentation outside of PB, look in the /developer/documention folder and select the type of documentation you're interested in.

For C/C++ projects you'll probably be interested in the Carbon framework. Select "carbon.html" for complete info on programming in the Carbon framework. In the description of the various functions, it tells you which header you need to #include. FYI, look into #import for header files instead. It's similar to #include but automatically prevents loading headers more than once in a single module.

I've used Borland stuff my whole life (till I bought this iMac). You probably won't have to specifically link in the required libraries (as you do in BC++). The default frameworks loaded with a particular project type will cover most if not all of the APIs you'll want. A lot of the project management stuff you're used to in BC++ (linking in specific libraries if needed, etc.) is pretty much taken care of for you in PB once you choose the project type for a new project.

You can mix C and C++ in the same project (as in BC++). Just keep them in separate modules. The file extensions are different than Borland (.c and .cpp). I think they're .m for C++ and .mm for C. PB will take care of that for you when you do a File/New. It'll ask you what type of file and, whether you choose C or C++, it'll provide the proper extension. Header files, if you select that type, are .h as in BC.

Have a good time!
 
For a random number between 0 and X the formula is rand()*X+1. C++ follows BEDMAS so you don't need any brackets in the formula.

You need to seed the rand() function before using it so you can get a truely random number.

To do that, you need to include the ctime header.

Then do srand(time(0)); to seed the random number generator with the system time.
 
I'm not sure if this applies to c++, but in c if you want a string of 10 chars you need an array 11 long:
char word[11];
The reason is that the last char in the array has to be a \0 (that's slash-zero), a string terminator, otherwise it'll keep reading off the end of the string...
 
Back
Top