Thread: I'm making a little addition Caclulator

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    2

    I'm making a little addition Caclulator

    I just started C++.

    Well this is what I have so far:

    Code:
     #include <iostream>
    
    using namespace std;
    
    int main()
    
    {
        string x;
        cout << "What is the first number you want to add?";
        cin >> x;
        cout << "The first number you want too add is: " << x << endl;
        cout << "  " << endl;
        string q;
        cout << "What is the second number you want to add?";
        cin >> q;
        cout << "The second number you want to add too " << x << " is " << q << endl;
        return 0;
    }
    My question is; What do I do too add X too Q. I did:
    Code:
    cout << x + q << endl;
    But all that does is make the two numbers side-by-side. So let's say the user chose 7 as the first number and 12 as the second. It would be:
    Code:
    712
    I want it too give me the answer instead of 712. So 7+12 is 19. So it would be:
    Code:
    19

  2. #2
    Registered User
    Join Date
    May 2008
    Posts
    87
    Some snippets from your code:

    Code:
    string x;
    ...
    string q;
    ...
    cout << x + q << endl;
    What is the result of "adding" two strings? How would you add the strings "Hi" + " there"? The language doesn't know that you have in fact read numbers in the the string variables. For strings, "add" means "concatenate".

    You can read in number values like double from stdin. Just change the types of x, q to double or int and give it another try.

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    2
    I figured it all out. It was supposed to be an int. Thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [C++] Need Help Making Menu Program
    By Bartvo in forum C++ Programming
    Replies: 2
    Last Post: 03-10-2010, 12:14 AM
  2. making sprites
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 02-20-2010, 07:00 AM
  3. OpenGL: Pixel addition
    By Hunter2 in forum Game Programming
    Replies: 4
    Last Post: 12-15-2008, 02:36 PM
  4. Making great graphics
    By MadCow257 in forum Game Programming
    Replies: 1
    Last Post: 02-20-2006, 11:59 PM
  5. thinking about making a network traffic monitor
    By jimjamjahaa in forum C++ Programming
    Replies: 9
    Last Post: 10-13-2005, 11:38 AM