Multiply.cpp
-
hi ich bin dabei C++ in 21 Tage durch zuarbeiten, habe auch also so gemacht wie im Buche:
doch bei Multiply.cpp kommt ein Fehler:
hier der Text aus dem Buch:
1: #include <iostream.h>
2: #include <conio.h>
3: #pragma hdrstop
4:
5: int multiply(int, int);
6: void showResult(int);
7:
8: int main(int argc, char **argv)
9: {
10: int x, y, result;
11: cout << endl << "Enter the first value: ";
12: cin >> x;
13: cout << "Enter the second value: ";
14: cin >> y;
15: result = multiply(x, y);
16: showResult(result);
17: cout << endl << endl << "Press any key to continue...";
18: getch();
19: return 0;
20: }
21:
22: int multiply(int x, int y)
23: {
24: return x * y;
25: }
26:
27: void showResult(int res)
28: {
29: cout << "The result is: " << result << endl;
30: }und hier meiner:
//---------------------------------------------------------------------------
#include <iostream.h>
#include <conio.h>
#pragma hdrstop//---------------------------------------------------------------------------
int multiply(int, int);
void showResult(int);int main(int argc, char* argv[])
{
int x, y, result;
cout << endl << "Enter the first value: ";
cin >> x;
cout << "Enter the second value ";
cin >> y;
result = multiply(x, y);
showResult(result);
cout << endl << endl << "Press any key to continue...";
getch();
return 0;
}int multiply(int x, int y)
{
return x * y;
}void showResult(int res)
{
cout << "The result is: " << result << endl;
}//---------------------------------------------------------------------------
habe Buchstabe für Buchstabe übernommen und es geht nicht..
Er sagt hier muss ein Fehler sein:
cout << "The result is: " << result << endl;
Fehlermeldung:
[C++ Fehler] Unit1.cpp(34): E2451 Undefiniertes Symbol 'result'
ändere ich allerdings res in result oder result in res kommt:
[Linker Fehler] Unresolved external '__ExitVCL' referenced from C:\PROGRAMME\BORLAND\CBUILDER6\LIB\CP32MTI.LIB|crtlvcl
Ein Freund meint mein C++ Builder ist falsch installiert....
Was ist denn nun wirklich Falsch?
greetings
Bass
-
Hallo
Das ist ein Standard C++ Konsolenprogramm, und damit gehört nicht hier ins Builder-Forum.
Dein Fehler beruht darauf, das du in der Funktion ShowResult() den Parameter verwenden must, und nicht eine Variable aus einer anderen, aufrufenden Funktionvoid showResult(int res) { cout << "The result is: " << res << endl; // res statt Result }/Edit : Bitte benutzt hier im Forum zum darstellen von Quellcode die C++ Code Tags. Diese findest du beim Erstellen eines Posts direkt links unter den Smilies.
/Edit : Und der Linker fehler kommt wahrscheinlich daher, das du diesen Quellcode nicht als Konsolenprogramm eingeben hast. Dazu must du Menü Datei/Neu/Konsolen-Experte ausführen, und dort die Option VCL verwenden deaktivieren.
bis bald
akari