Herzlich Willkommen, lieber Gast!
  Sie befinden sich hier:

  Forum » C / C++ (ANSI-Standard) » anfänger

Forum | Hilfe | Team | Links | Impressum | > Suche < | Mitglieder | Registrieren | Einloggen
  Quicklinks: MSDN-Online || STL || clib Reference Grundlagen || Literatur || E-Books || Zubehör || > F.A.Q. < || Downloads   

Autor Thread - Seiten: > 1 <
000
21.11.2006, 20:58 Uhr
noob1234



Erstmal Hallo
Ich bin ein absoluter noob in c++:
ich habe ein kleines programm geschrieben aber es hat einen Fehler.
Könnt ihr mir die Fehler in Code corrigieren.


C++:
#include <iostream>
using namespace std;

int plus(int, int);

int plus(a,b)
{
    int c=a+b;
    return c;
}

int main()
{
cout<<"gib zwei zahlen ein\n";
int zahl1;
cin>>zahl1;
cout<<"gib noch eine zahle ein\n";
int zahl2;
cin>>zahl2;
cout<<zahl1<<" plus "<<zahl2<<" gleich "<<plus(zahl1,zahl2)<<".\n";
}


 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
001
21.11.2006, 21:03 Uhr
~Sancho
Gast


int plus(int a, int b)

das ist alles
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
002
21.11.2006, 21:08 Uhr
noob1234



Wenn ich int plus(a, b) durch int plus(int a, int b) ersetze zeigt der compiter(Dev C++)
an, das in cout<<zahl1<<" plus "<<zahl2<<" gleich "<<plus(zahl1,zahl2)<<".\n";
ein Fehler ist
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
003
21.11.2006, 21:49 Uhr
xXx
Devil



C++:
#include <iostream>

int plus(int, int);

int main()
{
    std::cout << "Geben Sie bitte zwei Zahlen ein!" << std::endl;
    int nNumber1 = 0;
    int nNumber2 = 0;
    std::cin >> nNumber1;
    std::cout << "Geben Sie nun die zweite Zahl ein:" << std::endl;
    std::cin >> nNumber2;
    std::cout << nNumber1 << " plus " << nNumber2 << " ergibt: " << plus(nNumber1, nNumber2) << std::endl;

    return 0;
}

int plus(int a, int b)
{
    return (a + b);
}
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
004
21.11.2006, 21:52 Uhr
Spacelord
Hoffnungsloser Fall


Hi,
es gibt im Namensraum std schon etwas das plus heißt.

Du hast 3 Möglichkeiten:
- entweder du qualifizierst jeden Aufruf explizit mit std (und entfernst using namespace std)
- oder du benutzt using std::cout;using std::cin;(und entfernst using namespace std)
- oder du benennst(vernünftigerweise) deine Funktion um

Gruß Spacelord
--
.....Ich mach jetzt nämlich mein Jodeldiplom.Dann hab ich endlich was Eigenes.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
005
21.11.2006, 22:11 Uhr
noob1234



Ich habe es umgeschrieben:


C++:
#include <iostream>
using namespace std;

int plus2(int, int);
int minus2(int, int);

int main()
{
cout<<"gib zwei zahlen ein\n";
int zahl1;
cin>>zahl1;
cout<<"gib noch eine zahle ein\n";
int zahl2;
cin>>zahl2;
cout<<"1 oder 2\n";
int eingabe;
cin>>eingabe;
int op1=1;
int op2=2;
if(eingabe==1)
{
              cout<<zahl1<<" plus "<<zahl2<<" gleich "<<plus2(zahl1,zahl2)<<".\n";
}
if(eingabe==2)
{
              cout<<zahl1<<" minus "<<zahl2<<" gleich "<<minus2(zahl1,zahl2)<<".\n";
}
              
}

int plus2(int a,int b)
{
    return a+b;
}

int minus2(int c,ind d)
{
    return c-d;
}


aber der compielr zeigt bei   int minus2(int c,int d)  int has not been declared an.



Danke für die Hilfe
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
006
21.11.2006, 22:29 Uhr
Spacelord
Hoffnungsloser Fall


In dem Code da oben steht auch ind nicht int .

Gruß Spacelord
--
.....Ich mach jetzt nämlich mein Jodeldiplom.Dann hab ich endlich was Eigenes.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
Seiten: > 1 <     [ C / C++ (ANSI-Standard) ]  


ThWBoard 2.73 FloSoft-Edition
© by Paul Baecher & Felix Gonschorek (www.thwboard.de)

Anpassungen des Forums
© by Flo-Soft (www.flo-soft.de)

Sie sind Besucher: