Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Aufgabenblatt 3
- @author: Marc Brendecke
- @date: 16.04.2018
- */
- #include <stdio.h>
- #include <stdbool.h>
- #define ADDITION 'a'
- #define SUBTRAKTION 'b'
- #define DIVISION 'c'
- #define MULTIPLIKATION 'd'
- #define ENDE 'e'
- #define NULL 0
- void addieren(float zahl1, float zahl2);
- void subtrahieren(float zahl1, float zahl2);
- void dividieren(float zahl1, float zahl2);
- void multiplizieren(float zahl1, float zahl2);
- /* Funktion zum Addieren */
- void addieren(float zahl1, float zahl2) {
- float ergebnis = zahl1 + zahl2;
- printf(" %f + %f = %.3f\n", zahl1, zahl2, ergebnis);
- printf(" Ihr Ergbenis lautet : %.3f", ergebnis);
- }
- /* Funktion zum Subtrahieren */
- void subtrahieren(float zahl1, float zahl2) {
- float ergebnis = zahl1 - zahl2;
- printf(" %f - %f = %.3f\n", zahl1, zahl2, ergebnis);
- printf(" Ihr Ergbenis lautet : %.3f", ergebnis);
- }
- /* Funktion zum Dividieren */
- void dividieren(float zahl1, float zahl2) {
- if (NULL == zahl2) {
- printf("Man kann nicht durch Null teilen!\n\n");
- return;
- }
- /* Rechnung wird ausgeführt solange keine Null als zahl2 ausgewählt worden ist */
- else {
- float ergebnis = zahl1 / zahl2;
- printf(" %f / %f = %.3f\n", zahl1, zahl2, ergebnis);
- printf(" Ihr Ergbenis lautet : %.3f", ergebnis);
- }
- }
- /* Funktion zum Multiplizieren */
- void multiplizieren(float zahl1, float zahl2) {
- float ergebnis = zahl1 * zahl2;
- printf(" %f * %f = %.3f\n", zahl1, zahl2, ergebnis);
- printf(" Ihr Ergbenis lautet : %.3f", ergebnis);
- }
- int main(void) {
- char auswahl = 0;
- float zahl1 = 0.0f;
- float zahl2 = 0.0f;
- float ergebnis = 0.0f;
- while (true) {
- printf("Geben sie die erste Zahl ein:");
- scanf_s("%f", &zahl1);
- printf("\nGeben sie die zweite Zahl ein:");
- scanf_s("%f", &zahl2);
- printf("\nWaehlen sie eine Option aus: \n\na. Addition \nb. Subtraktion \nc. Division \nd. Multiplikation \ne. Ende \n\n");
- scanf_s("%c", &auswahl, 1);
- if (ENDE == auswahl) {
- printf("Das Program wird beendet.\n");
- break;
- }
- else if (ADDITION == auswahl) {
- addieren(zahl1, zahl2);
- }
- else if (SUBTRAKTION == auswahl) {
- subtrahieren(zahl1, zahl2);
- }
- else if (DIVISION == auswahl) {
- dividieren(zahl1, zahl2);
- }
- else if (MULTIPLIKATION == auswahl) {
- multiplizieren(zahl1, zahl2);
- }
- else if (auswahl < ENDE || auswahl > MULTIPLIKATION) {
- printf("Ihre Auswahl liegt ausserhalb der Auswahlmoeglichkeiten.\n\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement