Software informational articles

C++ tutorial 2, input and variables - software

 

This is the tutorial where we actually get into programming. Input and variables are the essence of programming. In this tutorial you will learn how to get data from the user and use variables. You will learn the types of variables there are and how to do basic math with them. At first, this may seem boring and pointless, but you have to learn it, and it ought to go quick.

Basic Input
When you are construction a console application, here is how you ought to get user input. Some of you may have guessed it, you use c[b]in[/b], of course, the 'c' gist console and the 'in' denotation input, like 'cout'. So, here is a basic code, where the name of the adjustable x. cin>>x;

Defining Variables
A alterable is what you guessed, a amount or piece of data that will vary.

The diffrent types of variables:

bool - true or false
int - whole numbers
char - atmosphere (a, b, c, etc. . . )
string - many typescript (words, etc. . )
float,double - facts that can have decimals

When deciding what type of capricious to use, think about what kind of data it is going to be storing and consider that some data types use more recollection than others, conversely most of your applications will use less reminiscence than you have. To proclaim a variable, write the type of variable, then the name.

Examples:
int myInt = 7;
char thisChar= 'a', otherChar = 'b', char newChar;
string password= "password";

Syntaxes
Notice how I all the time had the first word not capatalized, but I capatalized all the other ones. You can also characterize more than one at a time, and you dont continually need to set the value in the begining. Also, when you use a char, use a ' and for a line a ". Try to give your variables consequential names.

Math
This is certainly the heart of programming, math! For now, we are going to be doing some austere arithmetic.

The basic math functions are:

+ = addition
- = subtraction
/ = division
* = multiplication

There are a bunch more, but that is all we need for now.

Go out and make a program!

Now that you know some of that basic stuff, try assembly a program, and dont be anxious to ask for help on http://www. syschat. com!

Chris Silop - http://www. syschat. com, Laptop Forum


MORE RESOURCES:
Developed by:
home | site map
goldenarticles.net © 2018