i used tis code
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!!!!!!!!!!!
cout << "Enter the first number you would like to add" << endl ;
cin >> x;
cout << "You are planning to do " << x << " plus"<< endl ;
cin >> y;
z = x + y;
cout << x << " + " << y << "=" << z <<endl ;
there are string type varibles[/edit]
cmon, this is a basic question, im sure someone knows!
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.
i all figured it all out, i chaged the from string into float. i think double or int would work as well tho