Reputation: 27
I'm trying to make it so an input of a string gets multiplied by two the subtract 1. I know that my question has been asked here before, but the problem is that I couldn't really comprehend what it was saying was wrong.
string coffeeCode(string input) { //Coffee code= 2n-1 where n=a number in a string
vector<double> userInputDoubles;
istringstream converter(input);
string token;
double value{};
while (getline (converter, token, ',')) {
value = stod(token);
value = 2 * value - 1;
userInputDoubles.push_back(value);
};
return value;
};
Upvotes: 0
Views: 10277
Reputation: 16448
The function returns a double but its return type is string. There is no default constructor to convert double to string. Return a string:
std::string coffeeCode(std::string input) { //Coffee code= 2n-1 where n=a number in a string
std::vector<double> userInputDoubles;
std::istringstream converter(input);
std::string token;
double value{};
while (std::getline (converter, token, ',')) {
value = std::stod(token);
value = 2 * value - 1;
userInputDoubles.push_back(value);
};
return std::to_string(value);
};
or return a double:
double coffeeCode(std::string input) { //Coffee code= 2n-1 where n=a number in a string
std::vector<double> userInputDoubles;
std::istringstream converter(input);
std::string token;
double value{};
while (std::getline (converter, token, ',')) {
value = std::stod(token);
value = 2 * value - 1;
userInputDoubles.push_back(value);
};
return value;
};
Upvotes: 1