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.

Hilfe bei pointern

Empfohlene Antworten

Veröffentlicht

Hallo zusammen ich bin neu hier =)

ich hoffe mir kann jmd weiter helfen.

ich muss ein programm schreiben welches eine division durch führt und das mithilfe von pointern.

mein bisheriger code


#include<stdio.h>




                int division(dividend, divisor, anteil, rest)

                        {

                        int *erg1;

                        int *erg2;

                        int fehlercode;

                        if(dividend != 0 && divisor != 0)

                                {

                                anteil = dividend / divisor;

                                rest = dividend % divisor;

                                erg1 = &anteil;

                                erg2 = &rest;

                                fehlercode = 0;

                                }

                        if(divisor == 0)

                                {

                                fehlercode = 1;

                                }

                        if(dividend == 0 && divisor == 0)

                                {

                                fehlercode = 2;

                                }

                        return fehlercode;

                        }

int main()

                        {

                        int *erg1;

                        int *erg2;

                        int zahl1;

                        int zahl2;

                        int *dividend;

                        int *divisor;

                        int anteil;

                        int rest;

                        int fehlercode = division(dividend, divisor, anteil, rest);


                        printf("\nBitte geben Sie den Dividenden ein: ");

                        scanf("%d", &zahl1);

                        printf("\nBitte geben Sie den Divisor ein: ");

                        scanf("%d", &zahl2);

                        dividend = &zahl1;

                        divisor = &zahl2;


                        if(fehlercode == 0)

                                {

                                printf("\nDas Ergebniss lautet %d.%d", erg1, erg2);

                                }

                        if(fehlercode == 1)

                                {

                                printf("\nEs kann nicht duch 0 dividiert werden.");

                                }

                        if(fehlercode == 2)

                                {

                                printf("\nDas Ergebniss ist 0.");

                                }

                        return 0;

                        }

Nun hab ich folgendes Problem. Egal welche Zahlen eingebe. Es wird das Ausgegeben:

Das Ergebniss lautet 0.-559038737

Wo liegt das Problem?

Danke schonmal im vorraus.

moin

ja ein cc compiler auf einem unix system =)

hast du eine idee wie ich mein problem lösen kann?

Ja das komplette Programm ist Müll. Schau dir an wie Funktionsrümpfe aussehen sollen!

Falls du keine Pointer brauchst benutze sie nicht und noch wichtiger, falls du Pointer nicht verstehst benutze sie nicht!

Überlege dir den formalen Ablauf deines Programms. (hint: du führst ZUERST das Programm aus und fragst dann die Werte ab?)

Ansonsten wegen Pointern, die wollen auf etwas Zeigen, das steckt schon im Namen, vielleicht mal sehen das das überall passt!


#include <stdio.h>

int Division(int *dividend, int *divisor, int *result);

int main()
{
int dividend=-5;
int divisor=3;
int result=0;

if (divisor != 0)
{
int modulo=Division(&dividend, &divisor, &result);

printf("Divident: %d\nDivisor: %d\nErgebnis: %d\nModulo: %d\n", dividend, divisor, result, modulo);
}
}

int Division(int *dividend, int *divisor, int *result)
{
*result=(*dividend) / (*divisor);
return *dividend % *divisor;
}
[/PHP]

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

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.