Share your repls and programming experiences

← Back to all posts
Infinite Negative Numbers
SDGQ (3)

I'm a beginner in C++ and I created this. Compile and execute for it to work

Comments
hotnewtop
MrH0lmes (1)

Congratulations, SDGQ! You did a very good job!
By the way, taking in consideration the fact that you're a beginner, I'd like to give you some tips and tricks you could use to improve your coding skills:

• typing "std::" before every standard command can be something very unpleasant, annoying and, above all, boring, so, if you don't want to do that, you could simply put "using namespace std;" under the "#include ..." piece of code and, then, become free of those annoyances.

• Since you used the "for" loop function, you didn't have to use the expression "num--" inside its body, because you could simply determine, in the definitions of the "for" loop, that, after every loop, the num variable should decresce by one, and To do so, you just need to add one more parameter in the function mentioned:
for(int num = 0; num < 2;num--){

}

in conclusion, your code, after all the changes, should looks like this:

include <iostream>
using namespace std;
int main() {
for(int num = 0; num < 2;num--) {
cout << "NUMBER: " << num << "\n\n";
}
}

I hope i could help you and I wish you an awesome day, sir/lady!!
(I'm sorry about the grammatical mistakes...)

SDGQ (3)

@MrH0lmes thank you, this is very helpful!