Thread: help with simple calculator (beginner)

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    2

    help with simple calculator (beginner)

    Hello, I am very new to writing C++ and have started tryign to write a very basic calculator, capable of timesing, dividing, plussing or minusing two whole numbers.

    I could be way off with this effort, but this is the code so far. And the only errors I get are when in the 'if' sections and the error is:'ISO C++ forbids comparison between pointer and integer'

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    
    {
        int number1;
        char var;
        int number2;
        
    cout<<"Welcome to 'Phil's Calculator'\n";
    cin.get();
    cout<<"\nPlease choose a number \n";
    cin>> number1;
    cin.get();
    cout<<"\nNow choose your variable. *,/,+ or - \n";
    cin>> var;
    cin.get();
    cout<<"\nAnd finally, choose your second number \n";
    cin>> number2;
    cin.get();
    
    if ( var == "*") {
                cout<< number1*number2;
    }
    
    else if ( var == "/") {
         cout<< number1/number2;
          }
    else if ( var == "+") {
         cout<< number1+number2;
         }
         
    else if ( var == "-") {
         cout<< number1-number2;
         }
    else  cout<<"sorry, this program cannot do that";
        
    }
    Hope someone can tell me what i'm doing wrong, and how to fix the error.

    Thanks
    Phil

  2. #2
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    A single char isn't the same as a string, use '*', '/', etc. instead of "*", "/".

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2
    Thanks

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    37
    bear in mind that division by zero is not acceptable, so you should write an if statement for it telling the user about that problem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating very simple text editor using c
    By if13121 in forum C Programming
    Replies: 9
    Last Post: 10-19-2010, 05:26 PM
  2. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 11:48 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 05:48 AM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 08:52 AM