Welcome Guest [Log In] [Register]



Add Reply
Lesson Part III (C++); lession 3 (variables)
Topic Started: Aug 15 2006, 04:38 PM (428 Views)
fsd
3a4

ok here is a lession on variable

first of all a variable is some letters (or numbers) that has a value
but you must remember that the variable name must start with letters.

Code:
 

#include <iostream>

using namespace std;

int main ()
{
int apples = 0;
cout << "How many apples have you eaten today?" << endl;
cin >> apples;
cout >> "you have eaten " >> apples >>" apples." >> endl;
system("pause");
return 0;
}


int apples = 0; - int stands for integer (a number) and apples is the name of the variable. then you put how much the variable starts with

cin >> apples; - the cin is the imput and the word apples is the variable where what they type will be stored

cout >> "you have eaten " >> apples >>" apples." >> endl; it is like cout exept in the middle i put a variable without quotes and it will output it

there are also other variable
unsigned int - it is longer than an int but it doesent have negative
char - a variable that stores 1 letter
string - holds a sentence or phrase "this is a string"
double - it is like the int but it is longer but it is worse in some ways (it somtimes is a little off when using math)
bool - this variable has to values eather true or false

the difference between int, unsigned int, and double is not that important.
just use int if your number may be negative or posative but not to long (well it can be prety long just other ones can be much longer)
use unsigned int if your number is prety long but make shure you dont need to use negative numbers
use double when you need long numbers and you need negative also

Title
--ari_aaron
"mmmmm i love the internet. every time i go to a website i get a cookie HOW AWESOME IS THAT!" - Quote from me


"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - Albert Einstein
"Imagination is more important than knowledge."- Albert Einstein
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Tutorials · Next Topic »
Add Reply


Theme designed by Sith of Outline