Kleiner und größter Wert
-
Das ist noch etwas was mir im kopf rumschwirrt, aber irgendwie will es nich klappen...
int a, b, c
int d, e
d = min(a, b)
d = min(d, c)e = max(a, b)
e = max(e, c)cout << "kleinste: " << $d " grösste: " << $e;
-
Du kannst bei gerade mal 3 Zahlen entweder drei if abfragen verwenden oder besser eine for schleife, dabei solltest du die drei Zahlen aber besser in einem Array speichern.
if (z1>z2 && z1>z3) ...
int z[3]; //das array // ... int h=z[2]; int k=z[2]; for(int n=0;n<2;n++) { if (z[n]>h) h=z[n]; if (z[n]<k) k=z[n]; } //...
Ich hab das jetzt aber nicht kompiliert, evtl. fehler darfst du selber suchen...
-
@syphex
mach erstmal die $ weg, dann sollte es klappen.
edit: achso, ein "<<" und ein paar ";" fehlen auch.
-
Du kannst natürlich auch die tollen C++ Vektoren benutzen...
-
Cool, danke.
baue es gerade ein, bin mal gespannt ob es hinhaut. Hänge schon seit 1 Woche darüber...
-
Soweit bin ich jetzt. Nur irgendwie meldet er 2 Fehler, min und max sind undeclared identifier...
#include <iostream>
using namespace std;void main ()
{
int zahl_1,zahl_2,zahl_3,summe,mittelwert,produkt,k_wert,g_wert;cout << "Gebe drei ganze Zahlen ein: ";
cin >> zahl_1 >> zahl_2 >> zahl_3;summe=zahl_1+zahl_2+zahl_3;
mittelwert=(zahl_1+zahl_2+zahl_3)/3;
produkt=zahl_1*zahl_2*zahl_3;
k_wert = min(zahl_1, zahl_2);
k_wert = min(k_wert, zahl_3);g_wert = max(zahl_1, zahl_2);
g_wert = max(g_wert, zahl_3);cout << "\n\tDie Summe ist " << summe << endl;
cout << "\n\tDer Mittelwert ist " << mittelwert << endl;
cout << "\n\tDas Produkt ist " << produkt << endl;
cout << "\n\tDer kleinste Wert ist " << k_wert << endl;
cout << "\n\tDer groesste Wert ist " << g_wert << endl;
cout << endl;}
-
entweder du machst noch #include <algorithm>, da sind die drin, oder du programmierst sie dir selber.
-
@doppelmuffe:
Habe ich eingefügt, sagt immer noch das gleiche
-
syphex schrieb:
@doppelmuffe:
Habe ich eingefügt, sagt immer noch das gleichesagt er nicht vielleicht noch was? bei mir gehts nämlich sogar ohne...
(und mach aus dem "void main()" eine "int main()", bevor das noch jemand sieht..)
-
(16) : error C2065: 'min' : undeclared identifier
(19) : error C2065: 'max' : undeclared identifier
(30) : warning C4508: 'main' : function should return a value; 'void' return type assumeddas spuckt er an fehlermeldungen aus.
-
syphex schrieb:
(16) : error C2065: 'min' : undeclared identifier
(19) : error C2065: 'max' : undeclared identifier
(30) : warning C4508: 'main' : function should return a value; 'void' return type assumeddas spuckt er an fehlermeldungen aus.
hm. die dinger gibts aber definitiv in <algorithm>.
aber du musst sie wohl selber schreiben. kannst du das?
(und nochmal: die warnung in zeile 30 solltest du dringend beheben.)ich hab jetzt kurz nach deiner fehlermeldung gesucht (was du auch selber hättest machen können ;)), und das hier gefunden:
You must be using the default implementation of the standard library provided
with VC++, this is the dinkumware implementation. Microsoft did not include
max and min in <algorithm> to avoid confilicts with their stupid macros. They
want you to use _cpp_max() and _cpp_min() instead which are "equivalent"
templates. (are you starting to get a headache yet?). I kind of doubt that the ACE authors bothered to do this.
-
Sorry, bin in C++ nicht wirklich bewandert, kann aber etwas pascal.
Jetzt ging es, cool, vielen lieben Dank, hast mir weiter geholfen.