Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo zusammen,

möchte in meinem Programm über mehrere printf Behfele Text sowie eine dazugehörende Zahl ausgeben.

Der Text steht ganz normal links, die jeweilige Zahl soll aber rechtsbündig stehen. Die nachfolgenden printf Befehle, welche auch eine Zahl dann haben, soll auch rechtsbündig drunter stehen.

Hab da mal von irgendwelchen Flags gelesen?! kA ob dass das ist!

Wie realisiere ich das?

post-61024-14430448384015_thumb.jpg

Bearbeitet von zero61

Mit \t habe ich es bereits versucht (siehe unten) und dann kommt genau das raus was ich im Anhang gepostet habe

//-------------Ausgabe------------------------------------------


 printf("\nListenpreis:\t\t\t %.2f EUR\n",listenpreis);

 printf("-Rabatt %.0f %% \t\t\t %.2f EUR\n",rabatt,xa);

 printf("= Zieleinkaufspreis\t\t\t %.2f EUR\n",zieleinkaufspreis);

 printf("-Skonto %.0f %% \t\t\t %.2f EUR\n",skonto,xb);

 printf("= Bareinkaufspreis\t\t\t %.2f EUR\n",bareinkaufspreis);

 printf("+ Versandkosten\t\t\t %.2f EUR\n",versandkosten);

 printf("= Bezugspreis (Einstandspreis)\t\t\t %.2f EUR\n",bezugspreis);

Der Text steht ganz normal links, die jeweilige Zahl soll aber rechtsbündig stehen.
Die Zahlen sind rechtsbündig. Da du aber keine Breite angegeben hast, ist die Ausgabebreite für jede einzelne Zahl nur so groß, dass die jeweilige Zahl gerade eben hineinpasst.

Die Breite kannst du zwischen dem % und dem Punkt angeben, z.B. so:

"%8.2f"

Also mit der Breite funktioniert das nicht... oder ich hab das falsch angewendet.

Zum Verzicht auf printf .. geht leider nicht, da wir es so in der Schule lernen und nicht anders. Komm da sonst durch einander :D


//-------------Ausgabe------------------------------------------


 printf("\nListenpreis:\t\ %8.2f EUR\n",listenpreis);

 printf("-Rabatt %.0f %% \t %8.2f EUR\n",rabatt,xa);

 printf("= Zieleinkaufspreis\t %8.2f EUR\n",zieleinkaufspreis);

 printf("-Skonto %.0f %% \t %8.2f EUR\n",skonto,xb);

 printf("= Bareinkaufspreis\t %8.2f EUR\n",bareinkaufspreis);

 printf("+ Versandkosten\t %8.2f EUR\n",versandkosten);

 printf("= Bezugspreis (Einstandspreis)\t %8.2f EUR\n",bezugspreis);

post-61024-1443044838728_thumb.jpg

Mach die Tabs raus und sorg dafür, dass die Strings vor dem Formatfeld gleich lang sind.

hab das versucht, jedoch leider ohne Erfolg

oder füge jeweils noch tabs dazu, sodass du die zahlen untereinander bekommst.

in der 1. 2. 4. 6. jeweils zwei mal \t dazu und in der 3. und 5 jeweils 1 \t dazu.

dann sollte alles untereinander stehen

 printf("\nListenpreis:\t\t\t %8.2f EUR\n",listenpreis);

 printf("-Rabatt %.0f %% \t\t\t %8.2f EUR\n",rabatt,xa);

 printf("= Zieleinkaufspreis\t\t %8.2f EUR\n",zieleinkaufspreis);

 printf("-Skonto %.0f %% \t\t\t %8.2f EUR\n",skonto,xb);

 printf("= Bareinkaufspreis\t\t %8.2f EUR\n",bareinkaufspreis);

 printf("+ Versandkosten\t\t\t %8.2f EUR\n",versandkosten);

 printf("= Bezugspreis (Einstandspreis)\t %8.2f EUR\n",bezugspreis);

Tatsache, so hats geklapt! Frage mich jetzt nur wie du das rausbekommen hast .. Könnt ihr mir das erklären?!

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.