You don't need a function do do something as trivial as
out << num << std::endl;. I'd personally do it like this:
#include <iostream>
#include <fstream>
int writeNumbers(std::string filename, int start, int end);
int main ()
{
std::string filename;
int start, end;
std::cout << "Enter the name of the file you want to write to: ";
std::cout.sync(); // flushes the output buffer to make sure the string is shown
std::getline(cin, filename); // gets the entire line and stores it in "filename"
std::cout << "Enter the starting value: ";
std::cout.sync();
std::cin >> start; // gets the starting value and stores it in "start"
std::cout << "Enter the ending value: ";
std::cout.sync();
std::cin >> end;
writeNumbers(filename, start, end);
return 0;
}
bool writeNumbers (std::string filename, int start, int end)
{
std::ostream out(filename);
if (start < end)
{
for (int i = start; i <= end; i++)
{
out << i << std::endl;
}
}
else
{
for (int i = start; i >= end; i--)
{
out << i << std::endl;
}
}
out.close();
} I'll let you add the error-checking.