#include <iostream>
#include <string>
#include <sstream>
usingnamespace std; // I usually don't do this, but I'm not sure if 'ostringstream' is a member of 'std'.
string convert(int number, int digits);
int main(){
// blah blah blah
return 0;
}
string convert(int number, int digits) {
string converted;
ostringstream converter;
converter << number;
converted = converter.str();
converted = '$' + converted;
converted.insert(digits - 1,".");
return converted;
}
The function changes the number into a string, and then it uses some string functions to add a dollar sign and a decimal point to it. Call it by entering the number wanted to be converted, and then the amount of digits in the number.