New to c++ language. Need help.

Discussion in 'C++' started by Vanna Guo, Feb 9, 2010.

  1. Vanna Guo

    Vanna Guo New Member

    Joined:
    Feb 9, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    I know this is a ridiculous question but I've only just started to learn c++ a few days ago, I'm trying to figure out how to add 12 and 33 together. So I want the sum to display 45.

    this is what I have so far:

    #include <iostream>
    using namespace std;
    int main ( ) {

    int
    a = 12;
    b = 33;
    char sum;
    sum = a + b;

    cout << "The sum of 12 and 33 is " << sum;
    cout << "\n";

    return 0;
    }

    please help me and my stupidity, and thank you very much!
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Why on earth you are trying to add two numbers into a character?
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Code:
    int a=12;
    int b=33;
    int sum;
    sum=a+b;
    cout << a << "+" << b << "=" << sum << endl;
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice