

|
|
C/C++ Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
#include <string> #include <iostream> using namespace std; int main () { double ergebnis; double x; double y; double zeichen; string antwortja = "ja"; Start: cout << "\n\n"; cout << "****************************\n"; cout << "****** Taschenrechner ******\n"; cout << "****************************\n\n\n"; //Eingabe von Rechenart cout << "Druecken Sie [ ] und Enter...\n"; cout << "(1) fuer Addition\n"; cout << "(2) fuer Subtraktion\n"; cout << "(3) fuer Multiplikation\n"; cout << "(4) fuer Division\n\n"; rechenart: cout << "\n\n"; cout << "Geben Sie ihre Rechenart an: "; cin >> zeichen; cout << "\n"; //Eingabe der Rechenart if (zeichen > 4) { cout << "Sie muessen 1,2,3 oder 4 eingeben!"; goto rechenart; } //Rechenart 1 if (zeichen == 1) { cout << "Geben sie x an: "; cin >> x; cout << "Geben sie y an: "; cin >> y; ergebnis=x+y; cout << "------------------\n"; cout << "Das Ergebnis lautet: " << ergebnis; cout << "\n\n\n\n\n\n"; cout << "Neue Rechnung? "; cin >> antwortja; if (antwortja == "ja") { goto Start; } } //Rechenart 2 if (zeichen == 2) { cout << "Geben sie x an: "; cin >> x; cout << "Geben sie y an: "; cin >> y; ergebnis=x-y; cout << "------------------\n"; cout << "Das Ergebnis lautet: " << ergebnis; cout << "\n\n\n\n\n\n"; cout << "Neue Rechnung? "; cin >> antwortja; if (antwortja == "ja") { goto Start; } } //Rechenart 3 if (zeichen == 3) { cout << "Geben sie x an: "; cin >> x; cout << "Geben sie y an: "; cin >> y; ergebnis=x*y; cout << "------------------\n"; cout << "Das Ergebnis lautet: " << ergebnis; cout << "\n\n\n\n\n\n"; cout << "Neue Rechnung? "; cin >> antwortja; if (antwortja == "ja") { goto Start; } } //Rechenart 4 if (zeichen == 4) { cout << "Geben sie x an: "; cin >> x; cout << "Geben sie y an: "; cin >> y; ergebnis=x/y; cout << "------------------\n"; cout << "Das Ergebnis lautet: " << ergebnis; cout << "\n\n\n\n\n\n"; cout << "Neue Rechnung? "; cin >> antwortja; if (antwortja == "ja") { goto Start; } } } |
|
|
C/C++ Quellcode |
1 |
|

|
|
C/C++ Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
#include <string> #include <iostream> using namespace std; int main () { double ergebnis; double x; double y; double zeichen; string antwortja = "ja"; Start: cout << "\n\n"; cout << "****************************\n"; cout << "****** Taschenrechner ******\n"; cout << "****************************\n\n\n"; //Eingabe von Rechenart cout << "Druecken Sie [ ] und Enter...\n"; cout << "(1) fuer Addition\n"; cout << "(2) fuer Subtraktion\n"; cout << "(3) fuer Multiplikation\n"; cout << "(4) fuer Division\n\n"; rechenart: cout << "\n\n"; cout << "Geben Sie ihre Rechenart an: "; cin >> zeichen; cout << "\n"; //Eingabe der Rechenart if (zeichen > 4) { cout << "Sie muessen 1,2,3 oder 4 eingeben!"; goto rechenart; } cout << "Geben sie x an: "; cin >> x; cout << "Geben sie y an: "; cin >> y; //Rechenart 1 if (zeichen == 1) { ergebnis=x+y; } //Rechenart 2 if (zeichen == 2) { ergebnis=x-y; } //Rechenart 3 if (zeichen == 3) { ergebnis=x*y; } //Rechenart 4 if (zeichen == 4) { ergebnis=x/y; } cout << "------------------\n"; cout << "Das Ergebnis lautet: " << ergebnis; cout << "\n\n\n\n\n\n"; cout << "Neue Rechnung? "; cin >> antwortja; if (antwortja == "ja") { goto Start; } } |

|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
#include <string>
#include <iostream>
using namespace std;
int main ()
{
double ergebnis;
double x;
double y;
double zeichen = 1;
string antwortja = "j";
cout << "\n\n";
cout << "****************************\n";
cout << "****** Taschenrechner ******\n";
cout << "****************************\n\n\n";
//Eingabe von Rechenart
cout << "Druecken Sie [ ] und Enter...\n";
cout << "(1) fuer Addition\n";
cout << "(2) fuer Subtraktion\n";
cout << "(3) fuer Multiplikation\n";
cout << "(4) fuer Division\n\n";
cout << "\n\n";
cout << "Geben Sie ihre Rechenart an: ";
cin >> zeichen;
cout << "\n";
//Eingabe der Rechenart
if (zeichen > 4)
{
cout << "Sie muessen 1,2,3 oder 4 eingeben!";
return main();
}
cout << "Geben sie x an: ";
cin >> x;
cout << "Geben sie y an: ";
cin >> y;
//Rechenart 1
if (zeichen == 1)
{
ergebnis=x+y;
}
//Rechenart 2
if (zeichen == 2)
{
ergebnis=x-y;
}
//Rechenart 3
if (zeichen == 3)
{
ergebnis=x*y;
}
//Rechenart 4
if (zeichen == 4)
{
ergebnis=x/y;
}
cout << "------------------\n";
cout << "Das Ergebnis lautet: " << ergebnis;
cout << "\n\n\n\n\n\n";
/*
cout << "Neue Rechnung? ";
cin >> antwortja;
if (antwortja == "ja") // hier haben wir das problem, dass "JA" und "jop" nicht gehen!
{
goto Start; // goto ist keine gute Loesung.
}
*/
cout << "Neue Rechnung? j/n:\n";
cin >> antwortja;
if (antwortja == "j")
{
return main();
}
}
|

|
|
C/C++ Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
// Taschenrechner simpel // ToDo: // Operanten -> int oder besser ? // Bei der Division Sicherheitsabfrage einfügen! // Wenn der Rechner mehr leisten soll, dann ergaenzt ihn #include <iostream> using namespace std; int main () { int zeichen; int O1, O2; bool bigloop; do { cout << "Bitte geben Sie den 1. Operanten ein: "; cin >> O1; bool loop = false; do { cout << "Geben Sie die Rechenart ein ( (1) -> + (2) -> - (3) -> * (4) -> / )" << endl; cout << ", nur Zahlen von 1 bis 4 werden aktzeptiert. "; cin >> zeichen; if ((zeichen >= 1) && (zeichen <=4)) { loop = true; } else { cout << endl << " Rechenart nicht implementiert" << endl; } }while(!loop); cout << "Bitte geben Sie den 2. Operanten ein: "; cin >> O2; cout << endl; switch(zeichen) { case 1: cout << O1 << " + " << O2 << " = " << O1 + O2 << endl; break; case 2: cout << O1 << " - " << O2 << " = " << O1 - O2 << endl; break; case 3: cout << O1 << " * " << O2 << " = " << O1 * O2 << endl; break; case 4: cout << O1 << " / " << O2 << " = " << O1 / O2 << endl; break; default: cout << "\n\tSomething go's wrong"; break; } bigloop = true; cout << endl << " Zeichen eingeben - 9 für neue Aufgabe" << endl; // statt der 9 etwa in J/N oder Y/N aendern cin >> zeichen; if (zeichen == 9) { bigloop = false; } }while(!bigloop); } |

|
|
C/C++ Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
#include <cstdlib> #include <iostream> #include <string> using namespace std; int eingabe; float zahl1; float zahl2; float ergebnis; string eingabe1; int main() { cout << " " << endl; cout << " " << endl; cout << " TASCHENRECHNER " << endl; cout << " " << endl; cout << " " << endl; cout << "Möchten sie eine Addition(1) Multiplikation(2) Division(3)\n oder Subraktion(4) durchführen?"<< endl; cin >> eingabe; cout << "Erste Zahl :" << endl; cin >> zahl1; cout << "Zweite Zahl : " << endl; cin >> zahl2; switch (eingabe) { case 1: cout << "Ergebnis : " << zahl1+zahl2 << endl; break; case 2: cout << "Ergebnis : " << zahl1*zahl2 << endl; break; case 3 : cout << "Ergebnis : " << zahl1/zahl2 << endl; break; case 4 : cout << "Ergebnis : " << zahl1 - zahl2 << endl; break; } cout << "Möchten sie nochmal" << endl; cin >> eingabe1; if (eingabe1=="ja" || eingabe1=="Ja") { return main(); } system("PAUSE"); return EXIT_SUCCESS; } |