I got a small program here, I am just trying to return a string value from a function through a reference parameter but I keep getting an error. Any help or tips will be appreciated

#include<iostream>            
using namespace std; 

int timesTen(int, string&);



int main()
{
    int number = 6, product;

    string outcome = "positive";

    product= timesTen(number,outcome);

    cout << product << endl;



    return 0;
}



int timesTen(int value, string &result)
{
    int product;

if ( value < 0)
    result = "negative";

cout << result << endl;


product = (value*10);

return product;

}

It really helps if you tell us the error message you get, and what line it points to.

In your case, it looks to be a very simple fix - you need to include the string library if you want to use the string type.

#include <string>
And strictly speaking, you are not "returning" a string from your function. It returns an int, you're modifying the string parameter.

wow sweet thank you!

yea, thats what I was going for

thanks a lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.