My first project!

Discussion in 'Computer Programming, Emulation, and Game Modding' started by Boogieboo6, Jul 15, 2016.

  1. Boogieboo6
    OP

    Boogieboo6 @realDonaldTrump

    Member
    960
    1,315
    Jul 30, 2015
    United States
    I made a little calculator today! I'm still learning C++ so it might suck. I put up my project on MEGA. Here's the link to the exe. Here's the link to the cpp file. I was going to make it a 3ds calculator, but then thought that it'd be much easier to make for PC. There might be a trace of the original name still in there somewhere. Don't try to type in a letter when it asks for numbers, or it freaks out. 0 / 0 results in the answer shown as nan. That's all the problems I've found in it so far. I hope somebody likes it, or has some feedback for me!
     
  2. Dr_Doom

    Dr_Doom Advanced Member

    Newcomer
    95
    28
    Mar 10, 2016
    Cool good first project. I am no expert in C++ but you could try using a switch statement instead of all the if statement's

    KEEP CODING!! !!
     
  3. Cyan

    Cyan GBATemp's lurking knight

    Global Moderator
    18,754
    9,037
    Oct 27, 2002
    France
    Engine room, learning
    Good luck on learning C and C++ :)
    continue to practice (even if for the moment it's only following examples), that's how you learn. Just reading without practicing is not as good.
    Don't hesitate to try things by yourself, like adding checks for alpha instead of numerical values, prevent division by zero, etc.
    Don't worry too much if you don't know how to do something yet, it will probably be explained later.


    Do you already have a project in mind? having a project will be good to progress. You'll have something to achieve and will search how to do something by yourself. Even something small, like storing a list of names and phone numbers and email addresses for each of them. Adding a user, its info, retrieving a user data etc.


    As for the feedback about your code:
    try to keep the indentation of the code and the opening closing bracket consistent.
    For example :

    1)
    When you open a bracket, add an indentation.
    You did it in the wile and if loops, but you didn't add it to the main() function.
    line 8 to 55 could be indented by one tabs (4 spaces).

    It helps you see easily what your code is doing, where a function starts or ends.
    it might not seem very useful or necessary for the moment, but it's a good habit to get to be able to work with other developers later. keeping the "coding style" consistent is easier to read and take a project at a latter date without having to re-read it completely to understand what you wanted to do.

    2) you write this:
    Code:
    int main()
    {
    ....
    }
    then this:
    Code:
    while (...){
    ...}
    
    if(...){
    ...}
    On the first, you put the opening and closing bracket { } on their own lines, on the second one you write other code on the same line.
    Some developers like to open it on the same line, other prefer to open it on the next line, it's up to you. but keep it consistent.
    The end tag is always better on its own line, at the same indentation level than the command.
    Code:
    main()
    {
        if(some condition) {  <--- opening bracket here is fine, it's up to you to decide
        { <-- OR here, a lot of developers prefer to put it here, at the same level than the "if".
            indented code 
            inside the brackets
        } <-- closing bracket at the same level than the "if".
    }

    3)
    Not a mistake, but a recommendation : Comment your source.
    Like I said, if you come back to your code in one year, you will have to re-read everything if it's not well written (and oooh trust me, in one year you will be like "omg, what did I tried to code using this rudimentary functions????" "why did I do it this way???")
    So, always add comments.

    currently, you have :
    Code:
    if (choice == 1) do this
    if (choice == 2) do this
    if (choice == 3) do this
    How do you know what "choice2" should do ?

    add comments :
    Code:
    //Addition
    if (choice == 1) do this
    
    //Substraction
    if (choice == 2) do this
    
    //Multiplication
    if (choice == 3) do this
    4)
    You didn't do any mistake, this is just something you can read. keep it for later use, as there are a lot of things you don't know yet.

    It's about the "coding style" guideline.
    I mentioned "working with other developers", and it's easier to do if everyone work the same way.
    it's not something mandatory, just a guideline, like writing a variable :
    you wrote :
    int operation;

    you didn't wrote it
    int OpeRAtioN;

    using upper case randomly is 1) uggly, 2) hard to read, 3) no reason to do it.
    so, there's some guideline for when using uppercase or not, how to name a variable, etc.

    You can read some (random, I just google'd them) guidelines here :
    https://users.ece.cmu.edu/~eno/coding/CppCodingStandard.html
    http://geosoft.no/development/cppstyle.html
    http://www.doc.ic.ac.uk/lab/cplus/c++.rules/