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?
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...
#include <iostream>
#include <cstdlib> // *** required for using std::rand()
#include <ctime> // *** for std::time()usingnamespace 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);
}
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?
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.
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 :)
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