Quellcode Zusatzaufgabe 9

Dieses Programm berechnet auf 4 verschiedenen Wegen die Grundrechenarten (IF/SWITCH)

/* * * * * * * * * * * * * * * * 
* Name: Christian Klisch *
* Klasse: ITA 1b *
* Datum: 05.02.2000 *
* Dateiname: aufz5.c *
* Zweck: Rechenprogramm IF *
* * * * * * * * * * * * * * * */

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

void main()
{
//Deklaration der Variablen
int anzahl;
float zahl1,zahl2,ergebnis1,ergebnis2,ergebnis3,ergebnis4;
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
{


//Berechnung nach Strukturgramm 1
if(operation=='+')
{
ergebnis1=zahl1+zahl2;
}
if(operation=='-')
{
ergebnis1=zahl1-zahl2;
}
if(operation=='*')
{
ergebnis1=zahl1*zahl2;
}
if(operation=='/')
{
ergebnis1=zahl1/zahl2;
}



//Berechnung nach Strukturgramm 2
if(operation=='+')
{
ergebnis2=zahl1+zahl2;
}
else
{
if(operation=='-')
{
ergebnis2=zahl1-zahl2;
}
else
{
if(operation=='*')
{
ergebnis2=zahl1*zahl2;
}
else
{
if(operation=='/');
{
ergebnis2=zahl1/zahl2;
}
}
}
}



//Berechnung nach Strukturgramm 3
if(operation=='+'||operation=='-')
{
if(operation=='+')
{
ergebnis3=zahl1+zahl2;
}
else
{
ergebnis3=zahl1-zahl2;
}
}
else
{
if(operation=='*')
{
ergebnis3=zahl1*zahl2;
}
else
{
ergebnis3=zahl1/zahl2;
}
}



//Berechnung nach Strukturgramm 4
switch(operation){
case '+':
ergebnis4=zahl1+zahl2;
break;

case '-':
ergebnis4=zahl1-zahl2;
break;

case '*':
ergebnis4=zahl1*zahl2;
break;

case '/':
ergebnis4=zahl1/zahl2;
break;

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




//Ausgabe der Ergebnisse
printf("\n\nAusgabe der 4 Ergebnisse:\n\n1) %6.3f\n2) %6.3f\n3) %6.3f\n4) %6.3f",ergebnis1,ergebnis2,ergebnis3,ergebnis4);
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
}

Home << Schule << ITA-Mappe << Softwareentwicklung und Anmendung <<
Online: 1 | IP: | 16.04.2024 - 20:45:01  
©
Christian Klisch   - Alle Rechte vorbehalten - Impressum