-
Very simple question
Hi,
I am currently taking a tutorial about making video games. I have just started C++ and i dont understand what stuff to use for variables or whatever. Here is exactly what i dotn get.
When i wanna put a variable into my program i dont know what to use. How are all these different.i know all about their ranges and stuff but i just dont get what to use for what
C++ keyword
bool
char
unsigned char
short
unsigned short
long
unsigned long
int
unsigned int
float
double
I know ur probobly sitting in ur char laughing about my stupid question but cut me soem slack.
-
int, long, and short (as well as unsigned counterparts) are all integer types - they cannot hold decimal numbers
char (and unsigned char) is also an integral type, but is generally used when expressing letters
bool is either 'true' or 'false'
float, double, and long double are floating-point types - that is, they can hold decimal numbers
-
-
Simple solution:
1) Use int variables for integer values(whole numbers)
2) Use double variables for floats(numbers with decimal places)
3) Use char variables for characters.
4) Use bool variables if you want to store either true or false.
and don't worry about the others.
-
so then how comw this doesnt work?
#include <iostream>
int main (void);
{
char x;
std::cout << "Hi, whats your name?";
std::cin << x <<;
std::cout << "Your name is" << x;
return 0;
}
heres the error
: error C2447: missing function header (old-style formal list?)
-
just kidding! i mean this code
#include <iostream>
int main (void)
{
char x;
std::cout << "Hi, whats your name?";
std::cin >> x >>;
std::cout << "Your name is" << x;
return 0;
}
-
You don't need the extra '>>' operator on cin. Additionally, char only holds one character, to hold a string, you need to use either char*, or the 'std::string' class from the <string> header.