[C++] MultiCalc (WIP)

Discussion in 'Web Development and Programming' started by Wormwood, Dec 26, 2010.

  1. Wormwood

    Wormwood Regular Member

    29
    22
    64
    Hey. I've just recently taken learning C++ back up, and this is my first new project. It's kind of nooby, because I forgot most of what I learned before. This was just done today, with not a lot of time done reading up on more advanced methods. Features so far: Addition, and Celsius to Fahrenheit converter.

    Todo list:
    Subtraction
    Multiplication
    Dision
    Fahrenheit to Celsius converter
    Cleanup of code
    Make spacing of lines more easily readable
    Coloring (last, or near last)

    Preview of current version.


    Code...
    Code:
    //
    // Author: Ronald Munday
    // Date: 12/26/2010
    // Program:
    // MultiCalc - A calculator with multiple functions.
    // Addition
    // Multiplication
    // Subtraction
    // Division
    // Fahrenheit to Celcius
    // Celcius to Fahrenheit
    //
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    int funcAdd();
    int funcSub();
    int funcMulti();
    int funcDiv();
    int funcFtoC();
    int funcCtoF();
    int funcMain();
    
    int main()
    {
        system("title MultiCalc.exe - by Ronald Munday");
        int funcChoice;
        cout << "Hello, to start MultiCalc please choose from the following options. \nTo select one, please type the number and press enter.\n\n" << endl;
        cout << " 1. Addition\n 2. Subtraction\n 3. Multiplication\n 4. Division\n 5. Fahrenheit to Celsius\n 6. Celsius to Fahrenheit.\n\n" << endl;
        cin >> funcChoice;
    
        switch(funcChoice)
        {
            case 1:
                funcAdd();
                break;
            case 6:
                funcCtoF();
                break;
        }
    }
    
    int funcAdd()
    {
     int firstNumber;
     int secondNumber;
     int calcResult;
     cout << "You chose addition. Please enter the first number.\n";
     cin >> firstNumber;
     cout << "Now enter the second number.\n";
     cin >> secondNumber;
    
     calcResult = firstNumber + secondNumber;
    
     cout << "The result is: " << calcResult << endl;
    
     funcMain();
    }
    
    int funcSub()
    {
        cout << "VOID";
    }
    
    int funcMulti()
    {
        cout << "VOID";
    }
    
    int funcDiv()
    {
        cout << "VOID";
    }
    
    int funcFtoC()
    {
        cout << "VOID";
    }
    
    // The function to convert Celsius degrees into Fahrenheit
    // Fahrenheit = Celsius * (212-32)/100 + 32
    int funcCtoF()
    {
        int degCelsius;
        int convFactor = 212 - 32;
        int degFahrenheit;
        cout << "Celsius to Fahrenheit converter chosen.\n" << endl;
        cout << "Please eneter the degrees in Celsius: ";
        cin >> degCelsius;
    
        degFahrenheit = convFactor * degCelsius/100 + 32;
    
        cout << degCelsius << " is converted to " << degFahrenheit << "." << endl;
    
        funcMain();
    }
    
    int funcMain()
    {
        int backMain;
        cout << "Do you wish to back to the menu? Please choose.\n 1. Yes\n 2. No"<< endl;
        cin >> backMain;
    
        switch(backMain)
        {
            case 1:
                main();
                break;
    
            case 2:
                cout << "Thank you." << endl;
                cin.get();
                return 0;
            default:
                cout << "Please choose either 1 or 2." << endl;
                funcMain();
        }
    
    }
    
    To compile the code, you will need a C++ compiler. The one I used (and it works pretty well for free) is called Code::Blocks. If you are serious about programming, the download with MinGW is best.

    Downloads:
    http://www.codeblocks.org/downloads/26

    Normal download (Windows::non-MinGW):
    http://prdownload.berlios.de/codeblocks/codeblocks-10.05-setup.exe

    My .exe is included with the source code. (Not a virus, if you don't trust me compile the code yourself.)
     

    Attached Files:

    Last edited by a moderator: Jan 5, 2014
    Brandon likes this.
  2. Kaiser

    Kaiser Regular Member

    6,744
    1,132
    918
    No virus, download it. Looks great Ron keep it up bro.
     
  3. Wormwood

    Wormwood Regular Member

    29
    22
    64
    Thanks :) I'll be keeping it updated as I work on it. Once all the functions are at least working, I'll be adding the capability to do multiple equations for adding, subtracting, multiplication, and division. I don't think the temperature conversion really needs multiple equations. I'll also work on cleaning the code. This current code is very sloppy, I didn't even put many comments XD
    -- Merged Posts --
    Basic terminology of my above code...

    // - Comments, they will not appear in the program itself, and are just for editing purposes.
    { - beginning of any section of code
    #include <xxx> - Header files, essentially libraries containing all the commands I'm using.
    int funcAdd(), etc. - Function prototypes. I basically just declared these early so I would be able to use them later without worrying too much about order.
    int main() {} - Where the main program code is (between brackets {})
    int xxx() {} - Actual functions of the program.
    system - A system command
    int - an integer placeholder
    cout - Console output (text)
    cin - Console input (gets stored in appropriate placeholders)
    switch - Basically just a series of preset orders, that if met do certain functions.
    ; - ends all statements.
    { - ending of any section of code.
     
    Kaiser likes this.
  4. Kaiser

    Kaiser Regular Member

    6,744
    1,132
    918
    Nice explanation man, you really can do it. You will make it I remember the time when you first started c++ I think that was like 8 months ago?
     
  5. Wormwood

    Wormwood Regular Member

    29
    22
    64
    Actually a lot longer ago. Just more seriously 8 months ago.
     
    Brandon and Kaiser like this.
  6. Brandon

    Brandon Regular Member

    6,602
    1,707
    918
    I just saw this thread, I haven't messed with C++ but I do code in C# at work.
    Would love to see more examples of code. :)
     

Share This Page