Computerhilfen.de Logo
Forum
Tipps
News
Frage stellen

Hat dir diese Antwort geholfen?

Danke ButtonHilfreiche Antwort Button

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;
}

jaa danke jetzt gehts wieder suuuuuuuuper!!! ;D


« Graische Anwendungen programmierenJAVA: wie kann ich in eclipse die workbech auswählen? »
 

Schnelle Hilfe: Hier nach ähnlichen Fragen und passenden Tipps suchen!

Fremdwörter? Erklärungen im Lexikon!
Quellcode
Ein Quellcode, auch als Quelltext bekannt, bezeichnet den unkompilierten Programm-Code einer Software. Quell- oder Programm-Code ist der auch für Menschen lesbare Co...

Unicode
Unicode ist ein international anerkannter Standard, der als universeller Zeichencode ("Universal Code") dient und durch das Unicode-Konsortium entwickelt und verwaltet wi...

QR-Code
QR-Codes, die Abkürzung für "Quick Response Codes", sind eine Form von zweidimensionalen Barcodes. Damit lassen sich Informationen schnell und effizient speiche...