So I haven't been working at this long (about 2 weeks), but honestly I get passed the "very basics" and its just mumble jumble to me. Am I doing it wrong? or is it just not for me?
I am doing 2 different tutorials right now, (I got stuck on one and started another one)
I am doing the "learncpp.com" tutorials and I am stuck on 1.4 "a first look at functions"
the whole DoPrint() just doesn't make sense to me. I don't understand what it does, or why I would need it.
and the other tutorial is "TheNewBoston.com" video tutorials, and i'm stuck on tut. 13 "Using Variables in classes"
I'm just starting out as well and honestly the only way to learn is to just do it. You've got to write simple programs on your own. Just find sites that have you write simple programs and then search the web for how to go through each step of what you need to do. It will click a little better but you've just got to give it time.
So my "task" for one of my tutorials is to write a program that takes a number you input and double it, and then print it on the screen, this is what I came up with. Could someone please critique it. Thanks.
#include <iostream>
void doubleNumber(){
using namespace std;
int a = 0;
cout << "Enter a number: ";
cin >> a;
cout << a * 2;
Perhaps you should learn by reading a book. I personally can't take the online lecture material too well because I think the material is often times glossed over, although it's a good beginning. In the book I'm using I think the author goes a lot more in depth than many of the lectures you find on the internet, or perhaps it's just my preference.
Your code looks fine, although the function I think is overkill, unless of course your main point of writing the program is to familiarize yourself with functions. If it doesn't compile then I don't know what's wrong with it.
The code of your program looks fine, though I would have done it a bit different. The function name implies that the only thing the function does is double a number. I would have done it this way:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
usingnamespace std; // If you do this right after you include your libraries, it is only needed once.
int doubleNumber(int a) // This means that we will return some data of the int-type. We also have a single parameter of the int-type, which we will refer to as a.
{
return 2*a;
}
int main()
{
int input = 0;
cin >> input;
cout << doubleNumber(a);
system("pause");
return 0;
}
This guy breaks everything down into simple analogies and makes everything very clear. Just remember, practice practice practice practice practice. Follow along with everything he is doing, once you feel comfortable with the language start writing your own programs. Write a large program, watch a video, see how you can make your program better, see how you can make it do MORE.
Never assume you are too stupid, that's just stupid. :)
Good luck man. Email me if you need help understanding something. You don't need someone to show you why your program isn't working, you need someone to give you the tools to fix it yourself.
I normally don't write namespace inside of my function, BUT then I read some of the tutorials on "Learncpp.com" and thats what they did there, so I figured it was the proper way of doing it. But now I know.
Don't worry, it will click eventually, it took me a few months and then it all came together. Just stick with it best you can and keep practising different small programs.
Best thing to do as 'bool maybe' said, have books. Books everywhere, paper based, e-books, magazines (i think there are some you can get) and read them, then keep them as reference material, go back to them regularly.