Saturday, May 22, 2010

C++ Beginner Questions?

I have little experience with C++. I learned a small bit on my own earlier but I am in my first Intro to Comp Prog. course and just wrote a beginner program in there. My question is, How do I know when I need to add/use an integer, double, string, or char at the beginning or whenever in my code? Any site or help to get me jump started with this I will accept. Thanks

C++ Beginner Questions?
If you will need to store a value you will declare that type of variable. For example, if you need to store the number 10, you would use an int. If you want to store an IEEE-754 value, use a float. And so on and so forth.





You don't just go around adding ints and doubles to the beginning of your code. You have to actually use it. I suggest you read up on variables and data types and you won't be confused anymore.





A good C/C++ website with information and tutorials is www.cprogramming.com
Reply:You don't need to don't need to declare all of your variables at the beginning of your code in C++, and you don't need to know things ahead of time, you can always go back and edit, and this is a crucial part for programming.





But anyway, the differences are rather distinct. Use a string if you want words and so forth, use integers if you want generic numbers, but don't need decimal places, and use floats/doubles if you need accuracy.
Reply:That depends on what type of data you're going to be storing in the variable.





If you expect your variable to contain really small numbers, then use an "integer".


If you want decimal point precision use a "float".


If you need to store really really large numbers use a "double".


If you're going to be storing 8 bit ASCII codes (text characters), use "char".





More:


http://www.cplusplus.com/doc/tutorial/va...
Reply:http://www.wikipedia.org/

order flowers

No comments:

Post a Comment