This is a discussion on calculator within the C++ Programming forums, part of the General Programming Boards category; This is the first piece of code I have attempted to write in C++ and need some help getting it ...

  1. #1
    Registered User
    Join Date
    Feb 2012


    This is the first piece of code I have attempted to write in C++ and need some help getting it to do what I need it to. I am supposed to write a code for a calculator using only pointer and anonymous variables that continuously asks for different operations until the user wants to exit. This is what I have so far and it terminates after asking for the second number. Any help is appreciated, THANK YOU!
    using namespace std;
    int Arithmetic ( int * x , int * y );
    int main() {
    int num1;
    int num2;
    cout << "Please enter an integer value:"; // prompts user to enter number
    cin >> num1; //stores number
    cout << "Please enter a second integer value:"; // prompts user to enter number
    cin >> num2; //stores number
    Arithmetic( &num1,&num2 );
    return 0;
     Arithmetic(int * x, int * y)
    char * charPtr;
    int * intPtr2;
    while ( * charPtr != 'q' ){
            charPtr = newchar;
            cout << "Please select an operation:(+,-,*,/,%) or enter 'q' to exit"; // prompts user to enter and operation or 0 to exit
            cin >> *charPtr; 
    // stores user input
    switch ( *charPtr )
                    *intPtr2 = *x + *y;
                    *intPtr2 = *x - *y;
                    *intPtr2 = *x * *y;
                    *intPtr2 = *x / *y;
                    *intPtr2 = *x % *y;
                    cout << "invalid operation, enter 'q' to exit";
            cout << *intPtr2;

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Please edit your post so that the code doesn't have a crap-load of useless tags in it before you post it.

    [B ][SIZE=2 ][COLOR=#7f0055 ][SIZE=2 ][COLOR=#7f0055 ]#include[/COLOR ][/SIZE ][/COLOR ][/SIZE ][/B ][SIZE=2 ][COLOR=#2a00ff ][SIZE=2 ][COLOR=#2a00ff ]<iostream>[/COLOR ][/SIZE ][/COLOR ][/SIZE ]
    [B ][SIZE=2 ][COLOR=#7f0055 ][SIZE=2 ][COLOR=#7f0055 ]#include[/COLOR ][/SIZE ][/COLOR ][/SIZE ][/B ][SIZE=2 ][COLOR=#2a00ff ][SIZE=2 ][COLOR=#2a00ff ]<cmath>[/COLOR ][/SIZE ][/COLOR ][/SIZE ]

    That is, so your code looks like this
    using namespace std;
    That is, make sure you paste "text" as opposed to pasting "HTML" or some other overly decorated format.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support as the first necessary step to a free Europe.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Also make sure to indent your code.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. age calculator... :/
    By mikko93 in forum C Programming
    Replies: 3
    Last Post: 09-15-2011, 11:25 AM
  2. C++ Calculator Help plz
    By Caldark in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2010, 12:13 AM
  3. Calculator help
    By andreasleon in forum C++ Programming
    Replies: 4
    Last Post: 01-06-2007, 05:51 PM
  4. Please help with this calculator
    By Asbestos in forum C++ Programming
    Replies: 9
    Last Post: 03-08-2005, 12:00 PM
  5. Need help in RPN calculator
    By Lost__Soul in forum C Programming
    Replies: 14
    Last Post: 05-29-2003, 02:01 PM

Tags for this Thread

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21