Wednesday
Advanced Control Flow - For Loop
Lets say we wanted to repeat an operation multiple times on a set of data. Do we really want to write the code for it multiple times? Of course not. This is where loops come into play.
The Foor Loop
How would you calculate the factorial of 1-10 without using loops? Below would be one of many solutions.
cout << "!1 = " << factorial << endl;
factorial = factorial * 2;
cout << "!2 = " << factorial << endl;
factorial = factorial * 3;
cout << "!3 = " << factorial << endl;
factorial = factorial * 4;
cout << "!4 = " << factorial << endl;
factorial = factorial * 5;
cout << "!5 = " << factorial << endl;
//Ok! That’s a lot of work!
Would print out
!2 = 2
!3 = 6
!4 = 24
!5 = 120
Imagine doing this simple operation up to 100. Continue…
All entries filed under C++
no responses - Posted 06.25.08
By this time you should be familiar with the basics behind If and Else if statements. Below you’ll see more examples and more ways to use Control Flow in your programming.
1. You’ll learn more advanced ways of manipulating control flow in your program.
2. You’ll also learn how to declare and initialize boolean variables.
Boolean Variables
Boolean variables [...]
no responses - Posted 06.24.08
In the following tutorial, you’ll learn how to use if, and if-else statements. They are useful for deciding on what lines of code to execute based on values of previous variables in your program.
The If Statement
An example is as follows
int x;
if ( condition ) x = 50; //If condition returns TRUE, assign 50 to X.
In [...]
4 responses - Posted 06.22.08
In this tutorial you shall learn how to use
1. String Data Type
You should immediately notice that the declaration and assignment of a string is similar to int and doubles which you learned previously.
Declaring and Initializing the String
First make sure you have the appropriate headers in the file where you plan to use string objects.
#include <string>
using [...]
1 response - Posted 06.03.08
Want to start programming in C++? No worries. There is nothing to buy. It also isn’t difficult to get started! Anyone can learn! Talk Binary offers a variety of tutorials to get you started on the right track and right away! We’ll also step through every step of the process so you can get [...]
continue3 responses - Posted 05.31.08
In this tutorial I’ll show you how to write and compile a C++ Program using CodeBlocks in Windows. That’s right, Windows.
If you haven’t done so, download and install CodeBlocks
Using CodeBlocks to program Hello World
1. Open up CodeBlocks and simply click on “Create a new project”.
2 responses - Posted 05.29.08
Here is a step by step detailed guide on showing you how to write and compile a C++ program in Linux. For demonstration purposes, I’ll show you how to write and compile Hello World!
Difficult: Relatively Easy
How to write and compile Hello World in C++
1. First, let’s locate and open up our handy terminal.
