Calculator

This is a discussion on Calculator within the C++ Programming forums, part of the General Programming Boards category; I tried to make a very simple calculator. It works as such : Open the file... Hit [ENTER].... Type in ...

  1. #1
    Registered User
    Join Date
    Feb 2004
    Posts
    8

    Calculator

    I tried to make a very simple calculator. It works as such :

    Open the file...
    Hit [ENTER]....
    Type in one (1) number
    [Enter]
    Type in addition sign : +
    [enter]
    type in another number
    [enter]
    the result....wrong

    Anyway, here is the code...any suggestions?

    Code:
    #include <iostream>
    using namespace std;
    int main () {
        int first;
        int second;
        int answer;
        char sign;
        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
        cout<<"~~~~                 Calculator                      ~~~~\n";
        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
        cin>>first;
        cin>>sign;
        cin>>second;
        if (sign=='+') {
            answer = first + second;
            cout<<answer;
            }
        if (sign=='-') {
            answer = first - second;
            cout<<answer;
            }
        if (sign=='*') {
            answer = first * second;
            cout<<answer;
            }
        if (sign='/') {
            answer = first / second;
            cout<<answer;
            }
        cin.get();
        cin.get();
        return 0;
    }
    Thanks so much!

  2. #2
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Code:
        if (sign='/') {
    should be:
    Code:
        if (sign=='/') {

  3. #3
    Registered User
    Join Date
    Feb 2004
    Posts
    8
    Thanks so much!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need help modifying my calculator!!
    By Matus in forum C Programming
    Replies: 5
    Last Post: 03-25-2008, 12:03 PM
  2. GUI Calculator - Critique
    By The Brain in forum Windows Programming
    Replies: 1
    Last Post: 02-25-2006, 03:39 AM
  3. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  4. Need help with calculator program
    By Kate in forum C# Programming
    Replies: 1
    Last Post: 01-16-2004, 09:48 AM
  5. Replies: 2
    Last Post: 05-10-2002, 04:16 PM

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