View Single Post
Old 16-06-2006, 04:46 PM   #24
guesst
Abandonia Homie
 
guesst's Avatar

 
Join Date: May 2005
Location: Aurora, United States
Posts: 606
Default

So much to reply to! Warms my heart.

All of the programs posted here are in ANSI standard C, that is to say, not C++. If you want to eliminate some of the problems your complier is having with them, Abi79, save the files with a .C extention (not .cpp which is probably the default) and the compiler will (generally) compile it slightly differently.

@#BlakhOle#
I assume you're using DevCPP that I recomended at the start. Yes, "hello world" does come and go quickly. The problem is that when the program runs it opens a window, does the output, and closes the window before you get a chance to see what happened. There are two ways around this. One is to add the line
Code:
**getch();getch();
just inside the last bracket. This way the last thing the program will do is wait for you to input something before exiting. Try that first.

PS, Albi79, your hello world is not technically C++ code. It's a kind of bastardized hybred. A proper C++ program would use streams like this:
Code:
#include <iostream>
** int main(int argc, char **argv)
** {
**** char c;
****** 
**** std::cout << "Hello BlakhOle! Do you like C++? I bet you don't :P" << std::endl;
**** std::cin.get();
**** return (0);
** }
Which is why I don't write C++ code much yet. To do it properly is learning a whole new language. However, the above program you would want to tack on a .CPP extension or the compiler will likely bugger it up.

Back to #BlakhOle#'s question, as for getting the programs here to work the first thing to do when you compile them if they don't run is look at the frame that pops up at the bottom. It will give you any warnings or errors that may be impeeding the execution of the program. If you can't make heads or tails of them tell us which program you're running and post the error here and we'll see if we can't help out.

Ah, floats and ints. Well, there is a simple answer and a more complicated answer to that. Most books will take the complicated answer, explaining the inner workings of your computer and whatnot. I'll take the simple one.

char, int, and long are all the same thing in that they can be used to store only whole numbers, that is to say no decimals, no fractions. 1, 2, 3, 100, 121, etc. The difference in them is that a char can only hold number less than 256 if unsigned or between -127 and 128 if signed. It's very limited but works for certian things very well. Ints can hold bigger numbers than a char. Use them for your regular counting. Longs are for when you may need a really big number. If you try to put a number that's too big into a variable that can't hold it all sorts of wonky thinks can happen.

float and double are for holding numbers that may have decimal values. 1.1, 5.6, 10057.3, 3.14159, etc. Decimal points are a tricky thing for a computer to handle, so it's recomended that if you can do the job with whole numbers not to use floats as you're only going unnecessarly bog down your computer.

Well folks, I have an eye appointment, so that's all the time I have for now. Maybe I'll do mugwump later, maybe not until tomorrow. If you have any more questions, you know where to find me.

Ta
guesst is offline                         Send a private message to guesst
Reply With Quote