Unreal friendly naming

Comments are good in moderation. But it’s better to try and use descriptive variable names to tell other developers what a program does as opposed to an ungodly amount of comments

#include <iostream>


int main()
{
    std::cout << "Hello bois\n";
    std::cout << "It's time to screw up some mainframes\n\n";

    int a = 1;
    int b = 1;
    int c = 567837;

    std::cout << "It seems that you're attempting to hack into the accounts of\n"
                << "very important political operatives to uncover a mystery\n"
                << "that has left the public in disarray. With your years of\n"
                << "experience as a former FBI Hacker, this shouldn't be too\n"
                << "difficult for someone like you. You open your computer and \n"
                << "begin planning your attack, using your superior knowledge in\n"
                << "C++ to begin your mission of being a thorn in the governments\n"
                << "side. After days of researching and building the perfect code,\n"
                << "you launch your attack!\n\n"
                << "But it was all for naught. Before you allow your\n"
                << "program to run, you realize that the government has, for some odd\n"
                << "reason, decided that a security puzzle game that asks for the value\n"
                << "of 3 numbers after giving you their product and sum would be more\n"
                << "effective at detering any prying eyes. It seems that the FBI\n"
                << "had downgraded since you left.\n\n"
                << "With your trusty knowledge in basic Algebra, you continue your\n"
                << "journey through the government's security system.\n\n\n\n\n\n";

    std::cout << "PASSWORD: _ _ _" << std::endl;
    std::cout << "PRODUCT: " << a * b * c << std::endl;
    std::cout << "SUM: " << + a + b + c << std::endl;
    return 0;
}

My triplex game, sorry for it is on my native language cause it is more fun for me :smiley:


Serbian version

Here is my triplex game :slight_smile:
terminal

I find the simple variables are easy to read and to understand. In the code, I like to have commented so when I get back to the code, I would know where I am. We are all busy from time to time. Its all a learning curve and reading the code with the comments help me and maybe you out a lot as well.

#include <iostream> 

int main() 
{  
     // Intro lines.
    std::cout << "Help!!! I am stuck in a dungeon.";
    std::cout << std::endl;
    std::cout << "Find the right number combination to the door...";
    
    // Declaring 3 number code.
    const int a = 4;
    const int b = 3;
    const int c = 2;
    
    const int sum = a + b + c;
    const int product = a * b * c;

    // Print sum and product to terminal.
    std::cout << std::endl;
    std::cout << "There are 3 numbers in the code" << std::endl;  
    std::cout << "They all add up to "<< sum << std::endl;
    std::cout << "they all multiply to "<<product << std::endl; 
    
    return 0;

} this is my game.

Think of it this way… if the life of a piece of software is five or ten years, and YOU are no longer on the project, imagine being the poor schmuck that has to figure out what your intentions were ten years ago when he’s trying to maintain the codebase for a legacy app in some future company…

If we name variables correctly, we don’t need comments to explain what they do. Self-documenting code makes it easier to understand and read.

Effective variable naming certainly helps with the readability of code and reduces the requirement for commenting.

I personally used to like Hungarian notation where an initial lowercase letter or letters indicated the variableType and was then followed by the name, but to be honest modern code editors usually provide pop up declaration descriptions when you hover over a variable … so this is no longer needed.

My work so far.

HI good afternoon Gavin, im new to the course im only in section 2 triplex game, however the challenges are telling me to go to the community and post, I’ve signed up to every link Tristen sent via email but no responses so the question is where would I be able to get answer have a good day now and thank you

Privacy & Terms