New programmer seeking advice.

Hello everyone!

I am new here, also I have just been introduced to programming. I started programming 3 days ago and I've already spent around 30 hours reading and watching C++ related material. However, I'm not sure if I spend my time correctly. Do anyone with experience have any advice on how to do so?
Below I've posted a small part of a text-based RPG (se link). I thought that was a good place to start, because there's a lot of things going on in those types of games and a good way to practise functions and classes. I'm not hoping on actually producing a complete game - it's only for practise.

Question 1: Where do I start and what's most important to know well as a programmer?
Question 2: Why does not random() in my script work?

Thanks!

 
http://cpp.sh/5vrws 
Last edited on
Question 1
Well first you need to know the basics of the language, some testing and debugging skills and you need lots of practice.
Later you should learn about Clean Code, SOLID principles...

Question2
Your forgot to initialize the random generator with srand
http://www.cplusplus.com/reference/cstdlib/srand/

BTW Why did you choose C++ ?
> Question 1: Where do I start and what's most important to know well as a programmer?

See: https://isocpp.org/wiki/faq/how-to-learn-cpp#start-learning

> Question 2: Why does not random() in my script work?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <cstdlib> // *** required for using std::rand()
#include <ctime> // *** for std::time()

using namespace std;

void Attack(int level, int wepDmg)					//level and wepDmg (from main) are used in the equation for maxDmg.
{
    if(rand() % 8 == 0)					    //There's a 7/8 to deal damage and a 1/8 to miss.
    {
        cout << "You missed your attack.";
    }
    else
    {

        int Dmg = rand() % 4 +1;				//Random number between 1-4.
        int maxDmg = Dmg * (level) + wepDmg; 	//Previously rand. number * level + wepDmg

        cout << "You deal " << maxDmg << " physical damage to the dragon." << '\n' ;	//Printing out the damage done.
        cout << "int Dmg = " << Dmg << '\n' ;        //Printing out my randomized number.
    }

}

int main()
{
    // seed the legacy random number generator, once, at the start of the program
    // see: https://en.cppreference.com/w/cpp/numeric/random/srand
    std::srand( std::time(nullptr) ) ;

    string name;
    cout << "Welcome, please enter your name (first name, no spaces): ";
    cin >> name;
    // the above assumes that the entered name does not contain spaces

    cout << "Hi " << name << "!" " Here, take my sword and good luck slaying the dragon."<< endl;

    int lvl;
    cout << "Enter your level: " ;
    cin >> lvl;

    int AP;
    cout << "Enter the attack power of your weapon: " ;
    cin >> AP;

    Attack(lvl, AP);
}
Thomas1965 (4228) BTW Why did you choose C++ ?


I don't know. It felt like the mother language of programming and something everyone programmer should be able to code in.
I Googled some and found out that Python is the fastest-growing programming language, and by 2019 will significantly outstrip other languages in terms of active developers. Also, it seems to be a lot easier to learn and use. Programming is not a daily work/job for me, but I would like to create some casual games in the future. When GameMaker 2 Stuido is on sale I'll give that a try aswell.

Would it be better for me to learn Python, or why do people code in C++ to begin with?
Last edited on
3 days of programming? Gosh if 3 days is all it took you to learn all of this then I don't know what will stop you in life.. :O

BTW Why did you choose C++ ?


How about you Thomas, why did you choose C++?

Well since this is one of those snakes biting another snake's tail paradoxes, I'll bite my own tail instead to stop the paradox. I chose C++ because frankly I didn't. I'm learning it in school (till now we have learnt about arrays, basic user-defined functions and structures and that's about it we will learn this year in C++) and got interested. Time will tell which programming language suits me.. but C++ seems good so far. I guess it wouldn't hurt to know many languages at the same time though.
Last edited on
Nwb (303)


I realized it is the 2nd of December today, so I have actually been programming for 4 days. Anyway, I recognize my situation. I've been doing the same in many fields; music, painting, gaming, math, chemistry and even tap-dancing. I learn and absorb info rather quickly the first couple of weeks, then I stop learning and lose interest in what I'm doing. That usually ends with me leaving to never come back again. So, I stop myself in life :/

If no one suggest another language, I'll keep going with C++. I'm using Dev-C++ at the moment, but I'm hoping I can get Visual Basic soon.

Topic: Thanks for your help, I coded it like this: cpp.sh/8j33
I'll continue with the project and re-post it later :)

Last edited on
Personally I don't recommend C++ for beginners since it's the most complex and complicated language. I normally recommend beginners C#, Java or Python. All of them are suited for simple games.

I learned C++ because when I learned programming in the late eighties there were not that many options on a DOS PC or early Windows - never liked Basic. :(
Nowadays I only use it on the Forum here, I prefer C# and WPF
I'll keep going with C++. I'm using Dev-C++ at the moment, but I'm hoping I can get Visual Basic soon.


Visual Basic is a different programming language. Perhaps you meant Visual Studio.
Visual Basic is a different programming language. Perhaps you meant Visual Studio.


Yes, my bad. I mean Visual Studio 2017.

Topic archived. No new replies allowed.