wir lernen gerade c++ in der schule
wir sollen ein taschenrechner programmieren und dabei keine Funktion anwenden (irgendwie doof
also so weit bin ich alles klappt auch nur die nochmal-abfrage!
- Code: Alles auswählen
#include <iostream>
using namespace std;
int main()
{
char nochmal;
do
{
system ("cls");
float zahl1;
float zahl2;
char wahl;
cout.width(40);
cout.fill('*');
cout <<"Menu";
cout.width(40);
cout.fill('*');
cout <<"\n\n";
cout <<" <+> Addition\n";
cout <<" <-> Subtraktion\n";
cout <<" <*> Multiplikation\n";
cout <<" </> Division\n";
cin >> wahl;
switch (wahl)
{
case '+':
{
cout <<"Geben Sie die erste Zahl ein: ";
cin >> zahl1;
cout <<"\nGeben Sie nun die zweite Zahl ein: ";
cin >>zahl2;
cout <<"\nDas Ergebnis lautet "<< zahl1+zahl2;
break;
}
case '-':
{
cout <<"Geben Sie die erste Zahl ein: ";
cin >> zahl1;
cout <<"\nGeben Sie nun die zweite Zahl ein: ";
cin >>zahl2;
cout <<"\nDas Ergebnis lautet "<< zahl1-zahl2;
break;
}
case '*':
{
cout <<"Geben Sie die erste Zahl ein: ";
cin >> zahl1;
cout <<"\nGeben Sie nun die zweite Zahl ein: ";
cin >>zahl2;
cout <<"\nDas Ergebnis lautet "<< zahl1*zahl2;
break;
}
case '/':
{
cout <<"Geben Sie die erste Zahl ein: ";
cin >> zahl1;
cout <<"\nGeben Sie nun die zweite Zahl ein: ";
cin >>zahl2;
cout <<"\nDas Ergebnis lautet "<< zahl1/zahl2;
break;
}
default:
{
cout <<"\n\nFehler!";
cin.get();
cin.get();
}
}
cout <<"\n\nWollen Sie noch mal rechnen?(J/N) ";
cin >>nochmal;
while (nochmal!='J' || nochmal!='j' || nochmal!='n' || nochmal!='N')
{
cout <<"\nFalsche Angabe!Bitte Geben Sie es erneut ein: ";
cin>>nochmal;
if (nochmal=='n' || nochmal=='N')
{
cout <<"\n\nOK, CIAO\n";
cin.get();
cin.get();
return 0;
}
if (nochmal=='J' || nochmal=='j')
{
cout <<"\nCOOL COOL\n";
cin.get();
cin.get();
}
};
}while (nochmal=='J' || nochmal=='j');
cin.get();
cin.get();
return 0;
}
also brauch ich eigentlich nur die nochmalige abfrage, ich weiß aber nicht wie ich das machen soll( also nur mit funktionen oder goto) aber das sollen wir nicht benutzen
für jeden tip bin ich dankbar