Thread: C++ Calculator

Results 1 to 15 of 15
  1. #1
    Hyperion's Avatar
    Join Date
    Sep 2006
    Gender
    male
    Location
    NYC
    Posts
    8,287
    Reputation
    76
    Thanks
    1,245
    My Mood
    Lurking

    C++ Calculator

    I decided to make a math calculator because the math courses at my college had some geometry (Yes, this calculator also has geometry in it) in them.
    Of course, this saves so much time.
    I'm planning on adding formulas for more 3-d shapes soon.

    I'm not sure if this will work for you windows users since I programmed this with a mac.



    Souce code:

    /* C++ Calculator made
    by Hyperion */

    #include <iostream>
    using namespace std;

    int main ()

    {
    cout << "This calculator was programmed by Hyperion with c++.";
    cout << "\nPlease do not redistribute the program without the authorized";
    cout << "\nconsent of the programmer!";

    int a, j;
    double b, c, d, e, f, g, h, i, k, l, m, n, o, p, q;

    cout << "\nWelcome!!!\n";

    do
    {

    cout << "\nWould you like basic arithmetic calculator or geometry calculator?\n";
    cout << "\n(Basic Arithmetic = 1 | Geometry = 5):";

    cin >> a;

    if (a == 1)
    {

    cout << "\nWould you like to add, subtract, multiply, or divide?";
    cout << "\n(Add = 1 | Subtract = 2 | Multiply = 3 | Divide = 4):";

    cin >> a;

    if (a == 1)
    {
    cout << "Addition it is. Please enter your first number:";
    cin >> b;
    cout << "\nPlease enter a number to add with:";
    cin >> c;
    cout << "\nYour number is\n";
    cout << b + c;
    }

    if (a == 2)
    {
    cout << "Subtraction it is. Please enter a number:";
    cin >> d;
    cout << "Please enter a number to subtract with:";
    cin >> e;
    cout << "\nYour number is\n";
    cout << d - e;
    }

    if (a == 3)
    {
    cout << "Multiply it is. Please enter a number:";
    cin >> f;
    cout << "\nPlease enter a number to multiply with:\n";
    cin >> g;
    cout << "Your number is\n";
    cout << f * g;
    }

    if (a == 4)
    {
    cout << "Divide it is. Please enter a number:";
    cin >>h;
    cout << "Please enter a number to divide with:";
    cin >> i;
    cout << "\nYour number is\n";
    cout << h / i;
    }

    if (a > 4)
    {
    cout << "Program error!!!";
    }

    if (a < 1)
    {
    cout << "Program error!!!";
    }
    cout << "\nThanks for using the C++ Calculator!\n";
    }

    if (a == 5)
    {
    double r, s, t, u;

    cout << "\nWhat shape are you trying to find the area/volume of?\n";
    cout << "(Square = 1 | Triangle = 2 | Circle = 3 | Rectangle = 4 | Sphere = 5):";
    cin >> j;
    if (j == 1)
    {
    cout << "\nPlease enter the side length of the square:";
    cin >> k;
    cout << "\nThe area of the sqare is\n";
    cout << k * k;
    }

    if (j == 2)
    {
    cout << "\nPlease enter the base of the triangle:";
    cin >> l;
    cout << "\nPlease enter the height of the triangle:";
    cin >> m;
    n = l * m * .5;
    cout << "\nThe area of the triangle is\n";
    cout << n;
    }

    if (j == 3)
    {
    cout << "\nPlease enter the radius of the circle:";
    cin >> o;
    p = o * o;
    q = p * 3.14;
    cout << "\nThe area of the circle is\n";
    cout << q;
    }

    if (j == 4)
    {
    cout << "\nPlease enter the the width of the rectangle:";
    cin >> r;
    cout << "\nPlease enter the length of the rectange:";
    cin >> s;
    cout << "\nThe area if the rectangle is\n";
    cout << r * s;
    }

    if (j == 5)
    {
    cout << "\nPlease enter the radius of the sphere:";
    cin >> t;
    u = 1.33333333 * 3.14 * t * t * t;
    cout << "\nThe voluma of the sphere is\n";
    cout << u;
    }
    cout << "\nThanks for using the C++ Calculator!";
    }

    } while (a != 0);
    return 0;
    }
    Last edited by Hyperion; 09-05-2010 at 01:31 AM.

  2. The Following User Says Thank You to Hyperion For This Useful Post:

    [MPGH]Wyo (09-05-2010)

  3. #2
    Toxic Waltz's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    114
    Reputation
    14
    Thanks
    18
    nice try
    to use a switch.

  4. #3
    Hyperion's Avatar
    Join Date
    Sep 2006
    Gender
    male
    Location
    NYC
    Posts
    8,287
    Reputation
    76
    Thanks
    1,245
    My Mood
    Lurking
    Quote Originally Posted by Toxic Waltz View Post
    nice try
    to use a switch.
    Umm, what?

  5. #4
    Justin's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Melbourne, Australia
    Posts
    7,022
    Reputation
    1207
    Thanks
    2,825
    My Mood
    Inspired
    Couldn't you have compiled it into a .exe or a Windows Compatible Format!

    Minion Statistics

    Ex-Console Minion: 13/01/2011 ~ 19/04/2011
    Console Re-Minion: 14/06/2012 ~ 27/02/2013
    AVA Minion: 22/06/2012 ~ 12/11/2012
    Battlefield Minion: 04/02/2013 ~ 27/02/2013

    Computer Specifications
    Case: NZXT Phantom 820
    PSU: Corsair HX-850W V2
    Mobo: ASUS Z87-Deluxe
    CPU: Intel Core i7-4770K
    CPU Cooling: Swiftech H220 All-In-One Liquid Cooler (Cooled by 2x Noctua NF-F12 PWM 120mm Fans)
    RAM: Corsair Platinum Dominators CMD16GX3M2A2400C10 (2x8GB DDR3 2400Mhz XMP)
    GFX: ASUS GeForce GTX 770 DirectCU II OC 2GB
    Monitor: LG 29EB93 29" Ultrawide LED IPS Panel (2560x1080)(29:1 Ratio)
    Mouse: Razer Deathadder 2012
    Keyboard: Ducky DK 9008G2 Cherry MX-Brown Mechanical Keyboard


  6. #5
    Alen's Avatar
    Join Date
    Oct 2007
    Gender
    male
    Location
    Liquid Generator
    Posts
    27,928
    Reputation
    2539
    Thanks
    4,220
    My Mood
    Fine
    Quote Originally Posted by Hyperion View Post
    Umm, what?
    I think he's saying you should try to use a switch. And try making a function plotter (opengl), my attempt failed
    I'm Alen on Steam. RIP Skype Friday nights.

    I'm Navi's lover <span class="emoji-outer emoji-sizer"><span class="emoji-inner" style="background: url(chrome-extension://immhpnclomdloikkpcefncmfgjbkojmh/emoji-data/sheet_apple_64.png);background-position:2.5% 97.5%;background-size:4100%" title="hearts"></span></span>

    Messenger: Toxin about Dave | Paladin on Skyrim's AI | Dakota on JB | Royku leeching | Sjoerd's penis | Blitz's derpiness | Jason on Blitz
    Dave84311: God I've always wanted to eat crayons, with their vibrant colors. Only if they had taste.
    Mr. Lonely: @Alen I like making you wet, it makes me hard.


  7. #6
    Toxic Waltz's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    114
    Reputation
    14
    Thanks
    18
    Quote Originally Posted by Hyperion View Post
    Umm, what?
    The C switch Statement (C)

    and indent your code so it is easier to read.
    try to use as less variables as possible...

    there also is a C++ section on mpgh

  8. #7
    Expert at leaving women disappointed physically and emotionally.
    Premium Seller
    Premium Member
    Minionforce
    Wyo's Avatar
    Join Date
    Feb 2010
    Gender
    female
    Location
    Tijuana
    Posts
    23,279
    Reputation
    3511
    Thanks
    3,637
    My Mood
    Lurking
    Here didnt work in Windows Vista Ultimate but I got a Mac too so i will try there
     
    I smoke dix daily.
    I am Dix, and Arun is my master.
    I'M #1 NIGXMAS SCAMMER

  9. #8
    Hyperion's Avatar
    Join Date
    Sep 2006
    Gender
    male
    Location
    NYC
    Posts
    8,287
    Reputation
    76
    Thanks
    1,245
    My Mood
    Lurking
    Quote Originally Posted by Xion7200 View Post
    Couldn't you have compiled it into a .exe or a Windows Compatible Format!
    Yeah... I dunno how to do that.

    I did lay out the source code for you all so you can just copy and paste the source onto your compiler.

    Quote Originally Posted by Toxic Waltz View Post
    The C switch Statement (C)

    and indent your code so it is easier to read.
    try to use as less variables as possible...
    Ahh, I didn't get to that lesson yet.

    And it's the forum that won't show the indentations.

  10. The Following User Says Thank You to Hyperion For This Useful Post:

    Justin (09-05-2010)

  11. #9
    Justin's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Melbourne, Australia
    Posts
    7,022
    Reputation
    1207
    Thanks
    2,825
    My Mood
    Inspired
    Quote Originally Posted by Hyperion View Post
    Yeah... I dunno how to do that.

    I did lay out the source code for you all so you can just copy and paste the source onto your compiler.
    Awww.. I see, Thanks for Explaining!

    Minion Statistics

    Ex-Console Minion: 13/01/2011 ~ 19/04/2011
    Console Re-Minion: 14/06/2012 ~ 27/02/2013
    AVA Minion: 22/06/2012 ~ 12/11/2012
    Battlefield Minion: 04/02/2013 ~ 27/02/2013

    Computer Specifications
    Case: NZXT Phantom 820
    PSU: Corsair HX-850W V2
    Mobo: ASUS Z87-Deluxe
    CPU: Intel Core i7-4770K
    CPU Cooling: Swiftech H220 All-In-One Liquid Cooler (Cooled by 2x Noctua NF-F12 PWM 120mm Fans)
    RAM: Corsair Platinum Dominators CMD16GX3M2A2400C10 (2x8GB DDR3 2400Mhz XMP)
    GFX: ASUS GeForce GTX 770 DirectCU II OC 2GB
    Monitor: LG 29EB93 29" Ultrawide LED IPS Panel (2560x1080)(29:1 Ratio)
    Mouse: Razer Deathadder 2012
    Keyboard: Ducky DK 9008G2 Cherry MX-Brown Mechanical Keyboard


  12. #10
    Sjoerd's Avatar
    Join Date
    Jan 2008
    Gender
    male
    Location
    Aurora Borealis
    Posts
    16,876
    Reputation
    1198
    Thanks
    2,083
    My Mood
    Hot
    i actually expected a troll hyperion







  13. #11
    Lonesome Cowboy's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Location
    https://www.mpgh.net Posts: 12,475
    Posts
    5,377
    Reputation
    723
    Thanks
    1,403
    My Mood
    Brooding
    Way too high for me.
    Minecraft Wiki Manager since: 2012.12.16.
    Games Wiki Manager since: 2012.12.16
    Minecraft Section Minion: 2013.05.04.-2014.05.04
    League of Legends Section Minion: 2013.05.04.-2014.05.04
    Need for Speed World Minion: 2013.07.23.-2014.05.04
    Steam Games Section Minion: 2013.08.05.
    -2014.05.04
    Warrock Section Minion: 2013.10.09.
    -2014.05.04

    If you would like to become a Minecraft Wiki Editor, apply here!
    If you would like to become a Games Wiki Editor, PM me!

    Gifts:
    Gyongytyuk,Gyongytyuk,Zaps

  14. #12
    ALT©'s Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    312
    Reputation
    18
    Thanks
    11
    well good job i guess
    [/URL]


  15. #13
    Ryan's Avatar
    Join Date
    Jan 2009
    Gender
    male
    Posts
    7,924
    Reputation
    411
    Thanks
    998
    My Mood
    Relaxed
    Quote Originally Posted by Hyperion View Post
    And it's the forum that won't show the indentations.
    You should be able to wrap code tags around it...

    Code:
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    
    int main(int nNumberofArgs, char* pszargs[])
    
    {
    
        cout << "Welcome to Ryan's four function calculator." << endl;
        cout << "Functions are defined as follows: 1 - Add. 2 - Sub. 3 - Mult.";
        cout << " and 4 - Div." << endl;
        cout << "Please enter the function you desire by number." << endl;
        
        
        
        int choice;
        cout << "Enter 1, 2, 3, or 4:";
        cin >> choice;
        
        switch(choice)
        {
        case 1:         //addition case
                            
                            //enter first number
                            double num1;
                            cout << "Enter first number to be added:";
                            cin >> num1;
        
                            //enter second number
                            double num2;
                            cout << "Enter second number to be added:";
                            cin >> num2;
        
                            //calculate answer
                            double answer1;
                            answer1 = num1 + num2;
        
                            //declare answer
                            cout << "Answer is:";
                            cout << answer1 << endl;
                            
                            break;
                            
        case 2:             //subtraction case
                            //enter first number
                            double num3;
                            cout << "Enter number to be subtracted from:";
                            cin >> num3;
        
                            //enter second number
                            double num4;
        cout << "Enter second number to be subtracted from first:";
        cin >> num4;
        
                            //calculate answer
                            double answer2;
                            answer2 = num3 - num4;
        
                            //declare answer
                            cout << "Answer is:";
                            cout << answer2 << endl;
                            
                            break;
                            
        case 3:             //multiply case
                            //enter first number
        double num5;
        cout << "Enter first number to be multiplied:";
        cin >> num5;
        
        //enter second number
        double num6;
        cout << "Enter second number to be multiplied:";
        cin >> num6;
        
        //calculate answer
        double answer3;
        answer3 = num5 * num6;
        
        //declare answer
        cout << "Answer is:";
        cout << answer3 << endl;
        
        break;
        
        case 4:        //division case
        
        //enter first number
        double num7;
        cout << "Enter number to be divided:";
        cin >> num7;
        
        //enter second number
        double num8;
        cout << "Enter second number to divide by:";
        cin >> num8;
        
        //calculate answer
        double answer4;
        answer4 = num7 / num8;
        
        //declare answer
        cout << "Answer is:";
        cout << answer4 << endl;
        
        break;
        
        default:
        cout << "None of the four operations were chosen." << endl;
        
        }
        
    cout << "Thank you for using my quad operation calculator." << endl;
        
    system("PAUSE");
    
    return 0;
    
    }
    There's my first calculator. /
    I used a switch method in this one.
    It's not hard at all, you just state cases.
    It saves a lot of time as opposed to writing if statement after if statement.
    Last edited by Ryan; 09-05-2010 at 02:51 AM.

  16. #14

  17. #15
    Ryan's Avatar
    Join Date
    Jan 2009
    Gender
    male
    Posts
    7,924
    Reputation
    411
    Thanks
    998
    My Mood
    Relaxed
    Quote Originally Posted by Void View Post
    Noice Ryan. |:
    Lol. Definitely not.
    I'm doing more Java now.
    Getting into GUI's.

Similar Threads

  1. [C++]How to make a calculator
    By HypnoticBabeTrap in forum C++/C Programming
    Replies: 5
    Last Post: 12-05-2009, 09:33 AM
  2. Tiny bit more advanced calculator (Addition Only atm)
    By That0n3Guy in forum C++/C Programming
    Replies: 8
    Last Post: 11-17-2009, 04:32 PM
  3. VB 08 Calculator
    By mizzer3 in forum Visual Basic Programming
    Replies: 3
    Last Post: 11-13-2009, 10:21 AM
  4. Browse the Internets with CALCULATOR
    By noobhaxor47 in forum Programming Tutorials
    Replies: 3
    Last Post: 01-29-2009, 01:03 AM
  5. How to make a Basic Addition Calculator + Explenation
    By phoenixraider in forum C++/C Programming
    Replies: 4
    Last Post: 12-21-2008, 02:32 PM