I am creating a function that takes two integers and adds them returning as the string "a + b = c". I have to use the to_string function and it only seems to return the answer not the full equation.
Here is my code:
string additionToString(int a, int b)
{
string additions = inToString(a + b);
return addition;
}
#include <iostream>
#include <string>
std::string addition( int a, int b ) // assumes that a+b is within the range of int
{ return std::to_string(a) + " + " + std::to_string(b) + " == " + std::to_string(a+b) ; }int main()
{
for( int a : { 5, -23, 78, 0 } )
for( int b : { 17, 66, 1, -7 } )
std::cout << addition(a,b) << '\n' << addition(b,a) << '\n' ;
}