SonniE
09-25-2008, 03:11 PM
Im going to make a series of Beginners Tutorials for C++ programming since people on the forum are trying to learn it. going to add to this frequently and i will upload the project/source files so you can play with them.
1) Hello World
/*
SonniE's Hello World C++ Example 1
This Program Shows basic console printing skills
*/
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello World";
system("pause");
}
2) Input Output Strings
/*
SonniE's Input Output Example 2
*/
#include <iostream>
using namespace std;
int main()
{
//Creates The String userinput
string userinput;
//Prints To Screen
cout<<"Enter Your Name: ";
//Takes What User Typed in and puts it in userinput string
cin>>userinput;
//Prints Userinput String To Screen
cout<<userinput;
system("PAUSE");
}
3) Example usage of Define
#include <iostream>
#define pausethish0e system("pause");
#define showmetext cout
using namespace std;
int main()
{
showmetext<<"This Shows u What you can do with a define" << endl;
pausethish0e
}
4) Looping with Labels
#include <iostream>
#define pausethish0e system("pause");
using namespace std;
int main()
{
thisisalabel:
cout<<"Example oF Looping with a label" << endl;
pausethish0e
goto thisisalabel;
}
5) Looping with do while
#include <iostream>
#define pausethish0e system("pause");
using namespace std;
int main()
{
do{
cout<<"Example oF Looping with a while true" << endl;
pausethish0e
}while(true);
}
6) Breaking a Do while Loop
#include <iostream>
using namespace std;
int main()
{
do{
string ans;
cout<<"Example oF Looping with a while true with a break Enter '1' to Break the loop" << endl;
cin>>ans;
if(ans=="1")
break;
}while(true);
}
7) Simple Counting up (counts up to 10)
#include <iostream>
using namespace std;
int main()
{
for(int counter=0; counter<=10; counter++)
{
cout<<counter<<endl;
}
system("pause");
}
1) Hello World
/*
SonniE's Hello World C++ Example 1
This Program Shows basic console printing skills
*/
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello World";
system("pause");
}
2) Input Output Strings
/*
SonniE's Input Output Example 2
*/
#include <iostream>
using namespace std;
int main()
{
//Creates The String userinput
string userinput;
//Prints To Screen
cout<<"Enter Your Name: ";
//Takes What User Typed in and puts it in userinput string
cin>>userinput;
//Prints Userinput String To Screen
cout<<userinput;
system("PAUSE");
}
3) Example usage of Define
#include <iostream>
#define pausethish0e system("pause");
#define showmetext cout
using namespace std;
int main()
{
showmetext<<"This Shows u What you can do with a define" << endl;
pausethish0e
}
4) Looping with Labels
#include <iostream>
#define pausethish0e system("pause");
using namespace std;
int main()
{
thisisalabel:
cout<<"Example oF Looping with a label" << endl;
pausethish0e
goto thisisalabel;
}
5) Looping with do while
#include <iostream>
#define pausethish0e system("pause");
using namespace std;
int main()
{
do{
cout<<"Example oF Looping with a while true" << endl;
pausethish0e
}while(true);
}
6) Breaking a Do while Loop
#include <iostream>
using namespace std;
int main()
{
do{
string ans;
cout<<"Example oF Looping with a while true with a break Enter '1' to Break the loop" << endl;
cin>>ans;
if(ans=="1")
break;
}while(true);
}
7) Simple Counting up (counts up to 10)
#include <iostream>
using namespace std;
int main()
{
for(int counter=0; counter<=10; counter++)
{
cout<<counter<<endl;
}
system("pause");
}