Thread: problems adding

  1. #1
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608

    problems adding

    i used tis code

    PHP Code:
    cout << "Enter the first number you would like to add" << endl ;
    cin >> x;
    cout << "You are planning to do " << << " plus"<< endl ;
    cin >> y;
    y;
    cout << << " + " << << "=" << <<endl 
    but z is equal to x and y numbers combined like if x was 4 and y was 2 z would be 42. i am trying to make it so that if x was 4 and y was 2 it would equal 6. what am i doing wrong!!!!!!!!!!!

    [edit]there are string type varibles[/edit]
    Last edited by Klinerr1; 07-13-2002 at 05:07 PM.
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  2. #2
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    cmon, this is a basic question, im sure someone knows!
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    the problem is that they are strings, not numbers.

    the string classes operator+ function simply appends the numbers together as if they were text... so if x was 'c' and y was 'p', then z would be 'cp'. it's not treating 2 and 4 as numbers in your scenario, it's treating them as letters, that's why you get 42.

    dont use strings in this example. you should be using integers instead,then you won't have this problem.

    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  4. #4
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    i all figured it all out, i chaged the from string into float. i think double or int would work as well tho
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SVN Import Causes Crash
    By Tonto in forum Tech Board
    Replies: 6
    Last Post: 11-01-2006, 03:44 PM
  2. Java: Sorting and Adding a Row in Table
    By alphaoide in forum Tech Board
    Replies: 4
    Last Post: 08-12-2005, 08:22 PM
  3. Qt Manual problems
    By rip1968 in forum Linux Programming
    Replies: 0
    Last Post: 08-15-2002, 03:59 PM
  4. Replies: 3
    Last Post: 07-24-2002, 08:46 AM
  5. Coding Problems
    By RpiMatty in forum C++ Programming
    Replies: 12
    Last Post: 01-06-2002, 02:47 AM