hi bin neu hier - frage



  • Styler2008 schrieb:

    Nochmal eine frage zu den Tabellen sollen die so aussehen? Das ist ja dann an sich keine "richtige" Tabelle oder?

    cout<<"                             Jahr    Guthaben"<<endl;
        cout<<"                             2003     5250"<<endl;
        cout<<"                             2004     10762,5"<<endl;
        cout<<"                             2005     16550,625"<<endl;
        cout<<"                             2006     222628,156"<<endl;
    

    Eine vernüftige Einrückung wäre schon gut (damit hast du's ja 😉 ). Trennlinien wären noch besser, sind für eine Tabelle aber nicht nötig.



  • Ist beim Kopieren passiert 😉



  • Gut wäre, wenn die Euro-Beträge am Dezimaltrennzeichen ausgerichten wären (so dass alle Kommata untereinander stehen)!



  • So in etwa?

    //Jahres Kontostände.cpp - Kontostände für 10 Jahre
    #include <iostream>
    using namespace std;
    
    int main()
    {
        cout << "            Jahr         Guthaben" << endl;
        cout << "            2000           5000,00" << endl;
        cout << "            2001           5250,00" << endl;
        cout << "            2002          10762,50" << endl;
        cout << "            2003          16550,625" << endl;
        cout << "            2004         222628,15" << endl;
        cout << "            2005         236909,56" << endl;
        cout << "            2006         254005,04" << endl;
        cout << "            2007         271955,29" << endl;
        cout << "            2008         290803,05" << endl;
        cout << "            2009         310593,20" << endl;
        cout << "            2010         331372,86" << endl;
    
        system("PAUSE");
        return 0;
    }
    

    Hoffe es ist nicht wieder falsch 😃



  • Schande über mich so siehts besser aus:

    //Jahres Kontostände.cpp - Kontostände für 10 Jahre
    #include <iostream>
    using namespace std;
    
    int main()
    {
        cout << "            Jahr         Guthaben"  << endl;
        cout << "            2000           5000,00" << endl;
        cout << "            2001           5250,00" << endl;
        cout << "            2002          10762,50" << endl;
        cout << "            2003          16550,625"<< endl;
        cout << "            2004         222628,15" << endl;
        cout << "            2005         236909,56" << endl;
        cout << "            2006         254005,04" << endl;
        cout << "            2007         271955,29" << endl;
        cout << "            2008         290803,05" << endl;
        cout << "            2009         310593,20" << endl;
        cout << "            2010         331372,86" << endl;
    
        system("PAUSE");
        return 0;
    }
    


  • Ja, so sollte es aussehen. Wenn du das Ganze nun per Programm in einer (for-)Schleife erzeugst, hast du es geschafft.



  • Und jetzt schau dir einmal setw( int w ) etc an.

    Beispiel:

    #include <iomanip>
    // ...
    cout << setw(10) << datum << endl;
    //...
    

    http://www.cppreference.com/io_flags.html



  • Hab gerade einen anderen Auftrag bekommen(bin Praktikant an einer Bank)und muss diesem sofort nachgehen...

    Ich muss daher die Schleife erstmal zurückstellen.

    By the way:

    "Programming is similar to sex. If you make a mistake, you have to support it for the rest of your life."

    Ist genial 🙂

    Achso und

    Und jetzt schau dir einmal setw( int w ) etc an.

    Beispiel:
    C/C++ Code:
    #include <iomanip>
    // ...
    cout << setw(10) << datum << endl;
    //...
    C/C++ Code:
    #include <iomanip>
    // ...
    cout << setw(10) << datum << endl;
    //...
    C/C++ Code:
    #include <iomanip>
    // ...
    cout << setw(10) << datum << endl;
    //...

    Das verstehe ich nicht ganz @ Fellhuhn



  • Fellhuhn schrieb:

    Und jetzt schau dir einmal setw( int w ) etc an.

    Beispiel:

    #include <iomanip>
    // ...
    cout << setw(10) << datum << endl;
    //...
    

    http://www.cppreference.com/io_flags.html

    Musst du ihm das denn direkt verraten? 😉

    Na gut, dann hier gleich alles, was du brauchst: setw, fixed, setprecision.



  • Das sind Manipulatoren mit denen man die Art und Weise wie etwas ausgegeben wird beeinflussen kann. So kann man sich elende Folgen von Leerzeichen sparen und hat auch ein durchgängiges "Layout", wenn mal etwas mehr Stellen hat als vorgesehen.



  • Lies die Doku (MSDN). Das ist das A und O beim Programmieren. Wenn du trotzdem nicht weiter weißt, melde dich.



  • Hallo nochmal habe eine frage zu setw, fixed, setprecision also ich habe verstanden das das mainpulatoren sind.

    Aber wie man diese in ein Programm einbinden kann weiß ich leider nicht.

    Habe schon danach gegoogelt konnte jedoch keine Antwort finden.

    Matze könntest du mir das evt erklären? 😞

    Grüße Style



  • cout << setw(10) << meinWert << endl
           << setw(10) << meinAndererWert << endl;
    

    und so weiter. So einfach. 😉



  • Ah ok danke fellhuhn werde es sofort mal probieren 🙂



  • Vergiss nicht, iomanip zu inkludieren.



  • Fellhuhn schrieb:

    Und jetzt schau dir einmal setw( int w ) etc an.

    Beispiel:

    #include <iomanip>
    // ...
    cout << setw(10) << datum << endl;
    //...
    

    http://www.cppreference.com/io_flags.html

    😃 😉



  • Tya das warn bissi zu spät ;-P hatte nen Fehler das mit iomanip hab ich im i-net herrausgefunden 🙂


Anmelden zum Antworten