5 Replies - 558 Views - Last Post: 01 October 2012 - 07:07 PM Rate Topic: -----

#1 David7823  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 01-October 12

Simple Calculator Help

Posted 01 October 2012 - 01:46 PM

Hello!
I made a simple calculator but I can only use one digit numbers???
For example I can add 1 + 2 but not 11 + 22? I am new to c++ so i'm not sure what to do.

Here is my code:
#include <iostream>
using namespace std;
int main()
{
    int a;
    int b;
    int sum;
    
    cout << "Enter a number: \n";
    cin >> a;
    
    cout << "Enter another number: \n";
    cin >> b;
    
    sum = a + b;
    
    cout << "The answer is " << sum << endl;
    
    return 0;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Simple Calculator Help

#2 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1345
  • View blog
  • Posts: 4,618
  • Joined: 19-February 09

Re: Simple Calculator Help

Posted 01 October 2012 - 02:04 PM

That's strange usually int's can hold 10's of thousands. Do you get an error after you enter 11 and 22?
Was This Post Helpful? 0
  • +
  • -

#3 David7823  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 01-October 12

Re: Simple Calculator Help

Posted 01 October 2012 - 02:06 PM

Nope. I simply can't type more than one digit into Xcode?
Was This Post Helpful? 0
  • +
  • -

#4 David7823  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 01-October 12

Re: Simple Calculator Help

Posted 01 October 2012 - 02:14 PM

It must be an Xcode problem. I exported it and ran it in terminal and it works just fine.
Was This Post Helpful? 1
  • +
  • -

#5 Midi_  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 109
  • Joined: 22-May 12

Re: Simple Calculator Help

Posted 01 October 2012 - 06:52 PM

your program should work, are you using an xcode c++ file? thats strange man
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3575
  • View blog
  • Posts: 11,116
  • Joined: 05-May 12

Re: Simple Calculator Help

Posted 01 October 2012 - 07:07 PM

Out of curiosity, what result are you seeing when you enter 11 as the first number and 22 as the second number?

Is the result some wacky number? Is it always 0?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1