C++ Programming Guide [For newbs]
8 years 7 months ago #328664
Hello and welcome to C++ programming!
I have made this guide mainly to help others but also to improve myself. I have been going for a good 1 week! However i have learned loads and i'm looking for others in this community who has any knowledge or interrest in the language to hopefully share som. Hopefully if enought people are into this we can use this thread to share and help each other to improve.
The idea right now is to type your code in the topics and hopefully someone who has an idea to fix it will
it. I'm looking to improve the thread if it reaches high popularity along the users even tho everyone might not be interessted.
Rules
*If you're going to post a thread about your code not working or if you need any tips on how to make them better you should use Spoilers and preferably the:
Code Display
to make things look clean and proffesional.
*Don't spam immature comments on the thread. If player A thought he knew and tried to help you may not say: "OMG IDIOT IT'S NOT LIKE THAT". Feel free to stay argumentative but do not cross the line.
*Follow TOU.
FAQ:
Warning: Spoiler![ Click to expand ][ Click to hide ]
Q: What is C++?
A: C++ is a computer program that can make loads of softwares either on the internet or simply a program. You can make tons of things in the program such as games or programs that can help you to create big things.
Q: Why C++?
A: C++ is an old language indeed but it's been used in a butt load of programs and it's very often mentioned as one of the programs that can do a little more than most others.
Q: Is it hard to learn?
A: Yes one of the hardest if not the hardest.
Q: What program is recommended?
A: I suggest using either visual studios or if you're just looking to learn coding i believe Code Blocks is just fine (Which i'm currently using).
Guide to download it:
Warning: Spoiler![ Click to expand ][ Click to hide ]
and you press Binaries will show up. As most of you use windows i recomment taking the codeblocks-16.01mingw-setup.exe! version. It has no special features and is simple to use.
Step 3
After downloading the version you start the program > Create a new project > Choose Console application > Name it and just keep pressing next if you cannot be asked to read throught.
Step 4
You're now ready to start coding. You have been given an example on how a simple code looks like. Feel free to watch youtube or keep an eye open for this thread.
C++ Programming Guide [Help and Understanding]
8 years 7 months ago #328668
I'm going to start off with my own code here. It has some swedish words in it i'm sorry but you should understand most of it's values anyways. I'd appreciate ways to make it better. If you wonder what it does feel free to just copy it all and paste it onto your own codeblocks or whatever you're using. Thanks.
Warning: Spoiler![ Click to expand ][ Click to hide ]
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
bool kollaSvar(int tal1, int tal2, int svar)
{
int facit = tal1 + tal2;
if (svar != facit)
{
cout << endl << "Wrong :(" << endl;
cout << "Correct answer was " << facit << endl;
return false;
}
else
{
cout << endl << "Correct! " << endl << endl;
return true;
}
}
bool giveQuestion ()
{
int svar;
int facit;
bool IsCorrect;
int tal1, tal2;
srand(time(NULL));
tal1 = rand() % 10 + 1;
tal2 = rand() % 10 + 1;
facit = tal1 + tal2;
cout << "What is " << tal1 << "+" << tal2 << endl <<endl;
cin >> svar;
IsCorrect = kollaSvar(tal1, tal2, svar);
return IsCorrect;
}
void giveTest()
{
int TotalNumberOfQuestions = 3;
int TotalCorrect = 0;
int TotalWrong = 0;
for (int i=0; i< TotalNumberOfQuestions;i++)
{
bool IsCorrect = giveQuestion();
if (IsCorrect)
{
TotalCorrect++;
}
else
{
TotalWrong++;
}
}
cout <<endl << "You Completed A Total of " << TotalCorrect << " Out Of " << TotalNumberOfQuestions << endl << endl << endl << endl;
}
int main()
{
string NewTest = "";
do
{
giveTest();
cout << "Do you want to try again? [Y/N]" << endl;
cin >> NewTest;
}while(NewTest== "Y" || NewTest == "y" );
return 0;
}
C++ Programming Guide [Help and Understanding]
8 years 7 months ago #328677
Been trying to learn C++ but gave up easily, was to hard to understand. I was wondering how you started learning C++ and maybe help me learn C++ once again. ty
inb4 a wild soxey appears.
C++ Programming Guide [Help and Understanding]
8 years 7 months ago #328678
Glacial_Subzero wrote:
Been trying to learn C++ but gave up easily, was to hard to understand. I was wondering how you started learning C++ and maybe help me learn C++ once again. ty
inb4 a wild soxey appears.
The key to learn in the start is to keep going when your body tells no. Trust me, the few hours i forced myself to watch the video and learn code because i would not understand anything. Took me quite a while to figure out anything. However now after putting tons of hours i understand more and more and everything makes sense when you see others do it.
What i prefer to do is to watch a video then make a project based on what that video taught me. Repeat the code and make similar projects until you feel like you can move on. Repeat.
C++ Programming Guide [Help and Understanding]
8 years 7 months ago #328682
I'm going to make a few guides more but for now i'll teach you some of the more simple commands
When you write double backslash (//) The computer will completley ignore that code as it's used to comment what your code does.
When you use codes there is a thing similar to brackets that look like this { and }. They are used to make certain blocks. In these you should always end your code with a semicolon that looks like this ;.
At the start of every code there is a thing that says #include and for example <iostream>. iostream is an input system that allows you to use things like cout and cin.
After that there is using namespace std; which is like a template on following code.
int means interger and when it says main that is often the last thing you want to have in your code. For example if you add more code you want to have int main() as the last integer.
in this codeblock there is a simple command named
<< cout " Hello World" << endl;
return 0;
This simply says Hello World when you press start.
cout prints out the test that are written from keyboard.
endl creates a new line which is not needed but it makes things look nicer and more clean.
Return 0; simply tells the computer everything went fine and no more functions are to be added.
I made this part simple so you can simply read instead having to search throught google for 30 minutes just to find a basic guide on what everything does. Hopefully you can pick these up by time but don't think you're gonna learn these in a few minutes.
C++ Programming Guide [Help and Understanding]
8 years 7 months ago #328694
Aspect wrote:
Thezeus wrote:
Why would anybody seek for any programming help here?
And what videos are you using to learn C++?
Because this is a gaming community and games are made based on computer programs.
I have used these ones for a while but i usually scroll throught different videos for variety reasons but i can't remember to list them all.
On stackoverflow you'll get an informative, fast answer, and it's crucial for beginners to understand what happens behind their code, and in my opinion videos are not a good source of learning a programming language (I don't want to generalize, but I'm talking from the popular ones that I've seen).
In most cases sticking to a good book is the way to go, they usually explain much more than videos, and they teach you more than just the basics.
I would recommend "Thinking in C++" and "C++ Primer" as great books.
C++ Programming Guide [Help and Understanding]
8 years 7 months ago #328697
Thezeus wrote:
Aspect wrote:
Thezeus wrote:
Why would anybody seek for any programming help here?
And what videos are you using to learn C++?
Because this is a gaming community and games are made based on computer programs.
I have used these ones for a while but i usually scroll throught different videos for variety reasons but i can't remember to list them all.
On stackoverflow you'll get an informative, fast answer, and it's crucial for beginners to understand what happens behind their code, and in my opinion videos are not a good source of learning a programming language (I don't want to generalize, but I'm talking from the popular ones that I've seen).
In most cases sticking to a good book is the way to go, they usually explain much more than videos, and they teach you more than just the basics.
I would recommend "Thinking in C++" and "C++ Primer" as great books.
ex-minecraft owner, zarp legend (Was there during the infancy of Zarp), ex-ssrp admin, ex-teamspeak emblem (For SSRP admin & minecraft owner)
Login or register to post a reply.
C++ Programming Guide [Help and Understanding]
8 years 7 months ago #328706
Aspect wrote:
Thezeus wrote:
Aspect wrote:
Thezeus wrote:
Why would anybody seek for any programming help here?
And what videos are you using to learn C++?
Because this is a gaming community and games are made based on computer programs.
I have used these ones for a while but i usually scroll throught different videos for variety reasons but i can't remember to list them all.
On stackoverflow you'll get an informative, fast answer, and it's crucial for beginners to understand what happens behind their code, and in my opinion videos are not a good source of learning a programming language (I don't want to generalize, but I'm talking from the popular ones that I've seen).
In most cases sticking to a good book is the way to go, they usually explain much more than videos, and they teach you more than just the basics.
I would recommend "Thinking in C++" and "C++ Primer" as great books.
Sureley, thanks in advance!
No problem, and as you've said before, making projects is VERY important, it's really easy to get lost while learning programming.
Also you'll most likely appreciate google more than ever while learning, and you should check out msdn and stackoverflow.