matheraum.de
Raum für Mathematik
Offene Informations- und Nachhilfegemeinschaft

Für Schüler, Studenten, Lehrer, Mathematik-Interessierte.
Hallo Gast!einloggen | registrieren ]
Startseite · Forum · Wissen · Kurse · Mitglieder · Team · Impressum
Forenbaum
^ Forenbaum
Status Mathe
  Status Schulmathe
    Status Primarstufe
    Status Mathe Klassen 5-7
    Status Mathe Klassen 8-10
    Status Oberstufenmathe
    Status Mathe-Wettbewerbe
    Status Sonstiges
  Status Hochschulmathe
    Status Uni-Analysis
    Status Uni-Lin. Algebra
    Status Algebra+Zahlentheo.
    Status Diskrete Mathematik
    Status Fachdidaktik
    Status Finanz+Versicherung
    Status Logik+Mengenlehre
    Status Numerik
    Status Uni-Stochastik
    Status Topologie+Geometrie
    Status Uni-Sonstiges
  Status Mathe-Vorkurse
    Status Organisatorisches
    Status Schule
    Status Universität
  Status Mathe-Software
    Status Derive
    Status DynaGeo
    Status FunkyPlot
    Status GeoGebra
    Status LaTeX
    Status Maple
    Status MathCad
    Status Mathematica
    Status Matlab
    Status Maxima
    Status MuPad
    Status Taschenrechner

Gezeigt werden alle Foren bis zur Tiefe 2

Navigation
 Startseite...
 Neuerdings beta neu
 Forum...
 vorwissen...
 vorkurse...
 Werkzeuge...
 Nachhilfevermittlung beta...
 Online-Spiele beta
 Suchen
 Verein...
 Impressum
Das Projekt
Server und Internetanbindung werden durch Spenden finanziert.
Organisiert wird das Projekt von unserem Koordinatorenteam.
Hunderte Mitglieder helfen ehrenamtlich in unseren moderierten Foren.
Anbieter der Seite ist der gemeinnützige Verein "Vorhilfe.de e.V.".
Partnerseiten
Dt. Schulen im Ausland: Mathe-Seiten:Weitere Fächer:

Open Source FunktionenplotterFunkyPlot: Kostenloser und quelloffener Funktionenplotter für Linux und andere Betriebssysteme
StartseiteMatheForenElektrotechnikSelektion und Iteration
Foren für weitere Schulfächer findest Du auf www.vorhilfe.de z.B. Deutsch • Englisch • Französisch • Latein • Spanisch • Russisch • Griechisch
Forum "Elektrotechnik" - Selektion und Iteration
Selektion und Iteration < Elektrotechnik < Ingenieurwiss. < Vorhilfe
Ansicht: [ geschachtelt ] | ^ Forum "Elektrotechnik"  | ^^ Alle Foren  | ^ Forenbaum  | Materialien

Selektion und Iteration: Informatik
Status: (Frage) beantwortet Status 
Datum: 20:28 Do 17.11.2011
Autor: ak221993

Aufgabe
Implementieren sie das Programm. Benutzen SIe dabei eine switch-Anweisung für die Menüauswahl.


Ich habe diese Frage in keinem Forum auf anderen Internetseiten gestellt.



// Selektion und Iteration

#include <iostream>
using namespace std;

int main ()
{

    // Variablen deklarieren
    char wahl='x';
    int anzahl,zahl;
    double ergebnis;

    // Menueausgabe

while(wahl !='e'){
    ergebnis=0;
    cout << "Ihre [mm] Wahl?\n"; [/mm]
    cout << "a) Addition       s) [mm] Subtraktion\n"; [/mm]
    cout << "m) Multiplikation d) [mm] Division\n"; [/mm]
    cout << "e) [mm] Ende\n"; [/mm]
    cin >> wahl;

    switch(wahl)
    {
        case 'a':
                cout << "Wieviele Zahlen?";
                cin >> anzahl;
                for(int i=1;i<=anzahl;i++){
                    cout << "Zahl " << i << "=?";
                    cin >> zahl;
                    ergebnis = ergebnis+zahl;
                }
                cout << "Ergebnis = " << ergebnis << endl;  
                break;

        case 's':
                cout << "Wieviele Zahlen?";
                cin >> anzahl;      
                for(int i=1;i<=anzahl;i++){
                    cout << "Zahl " << i << "=?";
                    cin >> zahl;
                    ergebnis = ergebnis - zahl;
                }
                    cout << "Ergebnis = " << ergebnis << endl;  
                break;

            case 'm':
                    cout << "Wieviele Zahlen?";
                    cin >> anzahl;      
                    for(int i=1;i<=anzahl;i++){
                    cout << "Zahl " << i << "=?";
                    cin >> zahl;
                    ergebnis = ergebnis * zahl;
}
cout << "Ergebnis = " << ergebnis << endl;
                      
                    break;
            case 'd':
                    cout << "Wieviele Zahlen?";
                    cin >> anzahl;      
                    for(int i=1;i<=anzahl;i++){
                    cout << "Zahl " << i << "=?";
                    cin >> zahl;
                    if ("Zahl">0) {
                        ergebnis = ergebnis / zahl;
                    }

                    else ("Zahl"<0) {
                        cout << "Division durch 0";
                    }
cout << "Ergebnis = " << ergebnis << endl;

                    break;
}
}
}
system("PAUSE");

return 0;
                    }
Da funktioniert die MUlitplikation und die Division nicht!! Kann mir einer sagen was falsch ist bzw. was verändert werden muss ?!
Danke im Voraus .


        
Bezug
Selektion und Iteration: Antwort
Status: (Antwort) fertig Status 
Datum: 21:57 Do 17.11.2011
Autor: MathePower

Hallo ak221993,

> Implementieren sie das Programm. Benutzen SIe dabei eine
> switch-Anweisung für die Menüauswahl.
>  
> Ich habe diese Frage in keinem Forum auf anderen
> Internetseiten gestellt.
>  

1:
2: > // Selektion und Iteration
3: >   
4: > #include <iostream>
5: >  using namespace std;
6: >   
7: > int main ()
8: >  {
9: >   
10: > // Variablen deklarieren
11: >      char wahl='x';
12: >      int anzahl,zahl;
13: >      double ergebnis;
14: >   
15: > // Menueausgabe
16: >   
17: > while(wahl !='e'){
18: >      ergebnis=0;
19: >      cout << "Ihre Wahl?\n";
20: >      cout << "a) Addition       s) Subtraktion\n";
21: >      cout << "m) Multiplikation d) Division\n";
22: >      cout << "e) Ende\n";
23: >      cin >> wahl;
24: >   
25: > switch(wahl)
26: >      {
27: >          case 'a':
28: >                  cout << "Wieviele Zahlen?";
29: >                  cin >> anzahl;
30: >                  for(int i=1;i<=anzahl;i++){
31: >                      cout << "Zahl " << i << "=?";
32: >                      cin >> zahl;
33: >                      ergebnis = ergebnis+zahl;
34: >                  }
35: >                  cout << "Ergebnis = " << ergebnis << endl; 
36: >   
37: > break;
38: >   
39: > case 's': 
40: > cout << "Wieviele Zahlen?";
41: >                  cin >> anzahl;       
42: > for(int i=1;i<=anzahl;i++){
43: >                      cout << "Zahl " << i << "=?";
44: >                      cin >> zahl;
45: >                      ergebnis = ergebnis - zahl;
46: >                  }
47: >                      cout << "Ergebnis = " << ergebnis << 
48: > endl;   
49: > break;
50: >   
51: > case 'm':
52: >                      cout << "Wieviele Zahlen?";
53: >                      cin >> anzahl;       
54: > for(int i=1;i<=anzahl;i++){
55: >                      cout << "Zahl " << i << "=?";
56: >                      cin >> zahl;
57: >                      ergebnis = ergebnis * zahl;
58: >   }
59: >   cout << "Ergebnis = " << ergebnis << endl;
60: >                         
61: > break;
62: >              case 'd':
63: >                      cout << "Wieviele Zahlen?";
64: >                      cin >> anzahl;       
65: > for(int i=1;i<=anzahl;i++){
66: >                      cout << "Zahl " << i << "=?";
67: >                      cin >> zahl;
68: >                      if ("Zahl">0) {
69: >                          ergebnis = ergebnis / zahl;
70: >                      }
71: >  
72: > else ("Zahl"<0) {
73: >                          cout << "Division durch 0";
74: >                      }
75: >   cout << "Ergebnis = " << ergebnis << endl;
76: >  
77: > break;
78: >   }
79: >  }
80: >  }
81: >  system("PAUSE");
82: >   
83: > return 0;
84: > }


>  Da funktioniert die MUlitplikation und die Division
> nicht!! Kann mir einer sagen was falsch ist bzw. was
> verändert werden muss ?!


Bei der Multiplikation ist die Variable
ergebnis zu Beginn auf 1 zu setzen.

Es ist doch so, daß bei der bei der Subtrakion bzw. Division
die erste eingelesene Zahl der Minuend bzw. Dividend sein sollte.
Alle weiteren Zahlen sind Subtrahenden bzw. Divisoren.

Ist das auch hier so?

Falls ja, dann musst Du das Programm dahingehend ändern.


> Danke im Voraus .
>  


Gruss
MathePower

Bezug
Ansicht: [ geschachtelt ] | ^ Forum "Elektrotechnik"  | ^^ Alle Foren  | ^ Forenbaum  | Materialien


^ Seitenanfang ^
www.matheraum.de
[ Startseite | Forum | Wissen | Kurse | Mitglieder | Team | Impressum ]