Quellcode Aufgabe 11

Ein Taschenrechnerprogramm mit Unterfunktionen und bedingten IFs:

/* * * * * * * * * * * * * * * *
* Name: Christian Klisch *
* Klasse: ITA 1b *
* Datum: 22.02.2000 *
* Dateiname: aufg11-1.c *
* Zweck: Rechenprogramm IF *
* * * * * * * * * * * * * * * */

#include<stdio.h>
#include<conio.h>

//Funktionsprototypen
float add(float add1,float add2);
float sub(float minus,float minus2);
float mul(float a,float b);
float div(float zaehler,float nenner);


void main()
{
//Deklaration der Variablen
int anzahl;
float zahl1,zahl2,ergebnis;
char wiederholung,operation;

do{
//Programmstart mit Eingabe der Zahlen
clrscr();
printf("Taschenrechner\n\n Bitte geben Sie die Zahlen und die Rechenart an!\n\n Zahl1: ");

do{
gotoxy(9,5);
clreol();
fflush(stdin);
anzahl=scanf("%f",&zahl1);
}while(anzahl==0);

printf(" Zahl2: ");
do{
gotoxy(9,6);
clreol();
fflush(stdin);
anzahl=scanf("%f",&zahl2);
}while(anzahl==0);

do{
gotoxy(1,7);
printf("+ - * /: ");
clreol();
fflush(stdin);
scanf("%c",&operation);
//Nochmal bei falschem Rechenoperator
}while(operation!='+'&&operation!='-'&&operation!='*'&&operation!='/');



//Wenn bei Division zahl2=0 wird nichts berechnet
if(operation=='/'&&zahl2==0)
{
printf("\n\n \a !! Fehler !!\n\n\n");
}
else
{



//Strukturgramm nach Nr5
switch(operation){
case '+':
ergebnis=add(zahl1,zahl2);
break;

case '-':
ergebnis=sub(zahl1,zahl2);
break;

case '*':
ergebnis=mul(zahl1,zahl2);
break;

case '/':
ergebnis=div(zahl1,zahl2);
break;

default:
printf("\nFehler\n");
break;
}




//Ausgabe der Ergebnisse
printf("\n\nAusgabe des 1 Ergebnisses:\n\n1) %6.3f",ergebnis);
getch();

//Ende des IF bei / und 0
}

printf("\n\nNochmal?? Dann drcke 'j'");
fflush(stdin);
scanf("%c",&wiederholung);

//Wiederholung bei j
}while(wiederholung=='j');

//Ende MAIN
}


float add(float add1,float add2)
{
float addition;
addition=add1+add2;
return(addition);
}

float sub(float minus1,float minus2)
{
float subtraktion;
subtraktion=minus1-minus2;
return(subtraktion);
}

float mul(float a,float b)
{
float e;
e=a*b;
return(e);
}

float div(float zaehler,float nenner)
{
float zahl;
zahl=zaehler/nenner;
return(zahl);
}

Home << Schule << ITA-Mappe << Softwareentwicklung und Anmendung <<
Online: 1 | IP: | 12.04.2025 - 11:43:27  
©
Christian Klisch   - Alle Rechte vorbehalten - Impressum