OK, also der Einfachheit halber nochmal mit eingebauter in-Datei-Umleit-Funktion:
http://www.file-upload.net/download-848596/number.exe.html
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
void calculate( int a_number, bool a_file ) {
double result;
std::stringstream s;
s.setf( std::ios::fixed, std::ios::floatfield );
s.setf( std::ios::showpoint );
s << std::setprecision( 4 );
for( int i = 1; i <= a_number; i++ ) {
result = (double)a_number / (double)i;
s << a_number << "/" << i << " = " << result << std::endl;
}
if( a_file ) {
std::stringstream ss;
ss << a_number << ".txt";
std::ofstream outFile( ss.str().c_str());
outFile << s.str();
outFile.close();
} else {
std::cout << s.str();
}
}
int main( int argc, char *argv[] ) {
int number;
char c;
bool file = false;
if( argc == 2 ) {
calculate( atoi( argv[1] ), false );
} else {
std::cout << "Zahl eingeben: ";
std::cin >> number;
std::cout << std::endl;
std::cout << "Ausgabe in Datei umleiten (-> " << number << ".txt) (j/n)? ";
std::cin >> c;
std::cout << std::endl;
if( c == 'j' ) file = true;
calculate( number, file );
system( "PAUSE" );
}
return 0;
}