Variables are data storage in C++, and there are around 8 different types(I think). I will only show the most basic 3 types, because I dont want to open up Code::Blocks to tell the fourth one correctly.
Variable type #1[Int(integer variable)]
The variable type int is what you use when you want a program to hold a number value, for example
Variable type #2[float]=
The variable type float is used when you want to have a number with decimal places, for example:
Variable type #3[char(character variable) =
the variable type char is used when you want to hold letter values, and you declare the length like this:
those are the three most basic types of variables in c++, they should be sufficient for most of your coding needs, in the next tutorial I will post up some starting code for a text based game, and show you how to add in music, along with posting up my own text based game which I sadly deleted the Code::Blocks project so I dont have it's source code anymore . anyways, have a nice day.
Variable type #1[Int(integer variable)]
The variable type int is what you use when you want a program to hold a number value, for example
- Code:
#includes <iostream>
using namespace std;
int main()
{
int x;
cout <<"enter a number" << endl;
cin >> x;
system("PAUSE");
return 0;
}
Variable type #2[float]=
The variable type float is used when you want to have a number with decimal places, for example:
- Code:
#includes <iostream>
using namespace std;
int main()
{
float x;
x = 1.235486;
cout << "this is x " << x << endl;
system("PAUSE");
return 0;
}
Variable type #3[char(character variable) =
the variable type char is used when you want to hold letter values, and you declare the length like this:
- Code:
#includes <iostream>
using namespace std;
int main()
{
char x[128];//changing the number in the brackets changes the length
cout << "enter your name. " ;
cin >> x;
system("PAUSE");
return 0;
}
those are the three most basic types of variables in c++, they should be sufficient for most of your coding needs, in the next tutorial I will post up some starting code for a text based game, and show you how to add in music, along with posting up my own text based game which I sadly deleted the Code::Blocks project so I dont have it's source code anymore . anyways, have a nice day.