C++, suche Tutorial

Ah danke ich habe mich auch schon gefragt was das mit dem void eig. ist.
Ok jetzt habe ich das auch endlich mal mit der Quersumme kapiert. Thx an alle.

LG
silent12
 
void main() ist falsch, ich weiß nicht, wo alle das immer her nehmen, aber das ist laut C Standard ungültig ("Program behavior undefined"). In C++ ist es explizit verboten. Einige Compiler akzeptieren es trotzdem (Visual Studio z.B.) andere nicht.

Also entweder int main() oder int main(int argc, char *argv[]) aber bitte nicht void!

Naja void main deshalb weil die Funktion keinen Wert zurückgibt. So hat es uns der Info Prof erklärt.
 
Schau z. B. mal hier.

Noch nen anderes Zitat:
What's the deal with void main()
Under regular function calling/returning in C and C++, if your don't ever want to return anything from a function, you define it's return type as void. For example, a function that takes no arguments, and returns nothing can be prototyped as:
Code:
void foo(void);
A common misconception is that the same logic can be applied to main(). Well, it can't, main() is special, you should always follow the standard and define the return type as int. There are some exceptions where void main() is allowed, but these are on specialised systems only. If you're not sure if you're using one of these specialised systems or not, then the answer is simply no, you're not. If you were, you'd know it.
Be warned that if you post your "void main" code on the forums, you're going to get told to correct it. Responding with "my teacher said it's OK" is no defence; teachers have a bad habit of being wrong. Be safe, and post only standard code, and you'll find people concentrate on answering your other problems, rather than waste time telling you about this type of thing.
Quelle: cprogramming.com
 
Zuletzt bearbeitet:
Schade :D Wenn ich noch studieren würde, dann würde ich ihn drauf ansprechen warum er uns so einen Müll erzählt hat.
 
Bevor ihr noch lange diskutiert hätte ich noch mal eine Frage :-D :


#include <iostream>
using namespace std;


void set(int a)
{
a = 10;
}

int main()
{ int ziffer1, ziffer2, ziffer3, ziffer4,a,b,x,eingabe;
cout <<"Geben sie eine 4stellige Zahl ein" << endl;
cin >> eingabe;
eingabe div 1000 = ziffer1;
eingabe mod 1000 = a;
a div 100 = ziffer2;
a mod 100 = b;
b div 10 = ziffer3;
b mod 10 = ziffer4;
x = ziffer4*1000 + ziffer3*100 + ziffer2*10 + ziffer1;


set(x);
std::cout << x << std::endl;


system ("Pause");
}



Warum zeigt Dev c++ mir einen Fehler bei der ersten Rechnung mit "eingabe" an und wie könnte ich das Programm umformen, damit es nicht nur für 4stellige Zahlen funktioniert.
 
Zuletzt bearbeitet:
Ist das nicht genau das gleiche nur, dass div mit / und mod mit % getauscht wird und dadurch die Gleichung etwas umgestellt wird?
 
oh hab mich glaub vertan :D stimmt aber ich müsste doch eigentlich das mod und das div jeweils durch "/" und "%" ersetzen können oder nicht ?
 
Vor welcher Zuweisung, welchen operator ?

Oder wo sind jetzt noch Fehler ?


#include(iostream)
using namespace std;


int ziffer1, ziffer2, ziffer3, ziffer4,ziffer5, ziffer6, c, d, a,b,x,eingabe;


void set(int &a)
{
a = 10;
}




int main ()

{ cout << "Geben sie eine Zahl zwischn 1-10000 ein" << endl;
cin >>eingabe;


if (eingabe/1000 >1) {

eingabe / 1000 = ziffer1;
eingabe % 1000 = a;
a /100 = ziffer2;
a % 100 = b;
b / 10 = ziffer3;
b % 10 = ziffer4;
x = ziffer4*1000 + ziffer3*100 + ziffer2*10 + ziffer1;
}

if (eingabe/100 >1)
{ eingabe / 100 = ziffer1;
eingabe % 100 = a;
a / 10 = ziffer2;
a % 10 = ziffer3;
x = ziffer1*100 + ziffer2*10 +ziffer3; }

if (eingabe/10 >1)
{ eingabe / 10 = ziffer1;
eingabe % 10 = ziffer2;
x = ziffer1*10 + ziffer2; }

if (eingabe/10000 >1)
{
eingabe / 10000 = ziffer1;
eingabe % 10000 = a;
a / 1000 = ziffer2;
a % 1000 = b;
b / 100 = ziffer3;
b % 100 = c;
c / 10 = ziffer4;
c % 10 = ziffer5;
x = ziffer4*10000 + ziffer3*1000 + ziffer2*100 + ziffer1*10 + ziffer5;
}

Es wird mir ein Fehler bei dem cout... angezeigt!
 
An der Stelle wird die 1.Ziffer einer 4Stelligen Zahl abgetrennt ( Div rundet nicht ) Bsp.: 3432/1000 = 3 (1.Ziffer)
In manchen Teilen habe ich am Ende bei der Zusammenrechnung von x = die erste mit der letzten Ziffer vertauscht habe ich aber schon behoben
 
Drehe es um! Das Zuweisungsziel musst beim = immer links stehen!

Code:
ziffer1 = eingabe / 1000;

Der Compiler kann das nicht anders interpretieren! ;)
 
Zurück