C++ "nicht deklarierter Bezeichner"?

Hallo, Habe letztens mal ein Programm zur annähernden Berechnung von Pi geschrieben:

include include include include include include include

using namespace std;

int main() {

long double U; // = Umfang 
    long double GK; // = Gegenkathete 
    long double a; // = Winkel Alpha in Grad 
    long double AK=1; // = Ankathete 
    long double H; // = Hypotenuse 
    long double n; // = Anzahl Ecken des Vielecks 
long double b; // =zweiter Winkel
long double piAK; // =Verhältnis Umfang zu Ankathete
long double piH; // =Verhältnis Umfang zu Hypotenuse
long double pi; // =Näherungswert für pi

cout << "Wie häufig soll die Operation durchgeführt werden?" << endl;
cin >> n;
U=tan(180/n)*AK*2*n;
b=(n-2)*180*(1/n);
H=(b/2)*(1/cos(b));
piAK=U/AK;
piH=U/H;
pi=(piH+piAK)/2;
cout << piAK << endl;
cout << piH << endl;
cout << pi << endl;
cin.get();
return 0;

}

Wenn ich jetzt aber das Programm kompilieren will, bekomme ich folgende Fehlermeldungen:

1>c:\users\hauptkonto\documents\visual studio 2010\projects\pi\pi\pi_berechnung.cpp(23): error C2065: 'b': nichtdeklarierter Bezeichner 1>c:\users\hauptkonto\documents\visual studio 2010\projects\pi\pi\pi_berechnung.cpp(24): error C2065: 'b': nichtdeklarierter Bezeichner 1>c:\users\hauptkonto\documents\visual studio 2010\projects\pi\pi\pi_berechnung.cpp(24): error C2065: 'b': nichtdeklarierter Bezeichner 1>c:\users\hauptkonto\documents\visual studio 2010\projects\pi\pi\pi_berechnung.cpp(25): error C2065: 'piAK': nichtdeklarierter Bezeichner 1>c:\users\hauptkonto\documents\visual studio 2010\projects\pi\pi\pi_berechnung.cpp(26): error C2065: 'piH': nichtdeklarierter Bezeichner 1>c:\users\hauptkonto\documents\visual studio 2010\projects\pi\pi\pi_berechnung.cpp(27): error C2065: 'pi': nichtdeklarierter Bezeichner 1>c:\users\hauptkonto\documents\visual studio 2010\projects\pi\pi\pi_berechnung.cpp(27): error C2065: 'piH': nichtdeklarierter Bezeichner 1>c:\users\hauptkonto\documents\visual studio 2010\projects\pi\pi\pi_berechnung.cpp(27): error C2065: 'piAK': nichtdeklarierter Bezeichner 1>c:\users\hauptkonto\documents\visual studio 2010\projects\pi\pi\pi_berechnung.cpp(28): error C2065: 'piAK': nichtdeklarierter Bezeichner 1>c:\users\hauptkonto\documents\visual studio 2010\projects\pi\pi\pi_berechnung.cpp(29): error C2065: 'piH': nichtdeklarierter Bezeichner 1>c:\users\hauptkonto\documents\visual studio 2010\projects\pi\pi\pi_berechnung.cpp(30): error C2065: 'pi': nichtdeklarierter Bezeichner ========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========

Normalerweise würde ich jetzt sagen, dass der Schlamassel an einer Variabel liegt, die verwendet wird, ohne initialisiert worden zu sein, allerdings ist in diesem Code keine solche Variabel. Weiß einer, wie ich das hier fixen kann?

Fehler, programmieren, Cplusplus, Error
C++ Snake programmieren, aber wie?

Hallo, ich schreibe gerade an einem Spiel(Snake) in c++. Ich weiß aber nicht wie ich die punkte einfüge die die schlange dann einsammeln kann, wie ich die Schlange länger mache und wie ich die kollision zwischen schlangenkopf und schlangenkörper integriere.

Hier mein bisheriger code:

include <conio.h> include <Windows.h> include

using namespace std;

const int rechts = 'd'; const int links = 'a'; const int hoch = 'w'; const int runter = 's'; const int prechts = 0x4d; //Hexadezimale codes der Pfeiltasten const int plinks = 0x4b; const int phoch = 0x48; const int prunter = 0x50;

void Bewegung(int, int);

int main() { bool ende = false; int x = 12; //x Koordniate (erst definition = Startpunkt) int < = 10; //y Koordniate (erst definition = Startpunkt) int richtung = 1; int punkt = 0;

cout << "Punkte " << punkte << endl; cout <<"XXXXXXXXXXXXXXXXXXXXXXXXX"<<endl; for(int i = 1; i < 24; i++) { cout << "X X"<<endl; } cout <<"XXXXXXXXXXXXXXXXXXXXXXXXX"<<endl;

do { Bewegung(x, y); cout << "o";

if(kbhit()) { int taste = getch(); if(!taste || taste == 0xe0)) taste = getch();

if(taste == hoch && richtung != 2 || taste == phoch && richtung != 2) { richtung = 1; --y; }

else if(taste == runter && richtung != 1 || taste == prunter && richtung != 1) { richtung = 2; ++y; }

else if(taste == rechts && richtung != 4 || taste == prechts && richtung != 4) { richtung = 3; ++x; }

else if(taste == links && richtung != 3 || taste == plinks && richtung != 3)

else { continue; }

Sleep(150); }

else if(!kbhit()) { if(richtung == 1) { --y; } if(richtung == 2) { ++y; } if(richtung == 3) { ++x; } if(richtung == 4) { --x; } Sleep(150); }

system("cls");

if( x <= 0 || x >= 24 || x <= 1 || y >= 25) { cout << "Game Over!" << endl << endl; cout << "Du hast " << punkte << " Punkte erreicht" << endl << endl; system("pause"); return 0; }

cout << "Punkte " << punkte << endl; cout <<"XXXXXXXXXXXXXXXXXXXXXXXXX"<<endl; for(int i = 1; i < 24; i++) { cout << "X X"<<endl; } cout <<"XXXXXXXXXXXXXXXXXXXXXXXXX"<<endl;

}while(true);

return 0; }

void Bewegung(int b, int h) { COORD punkt; punkt.X = b; punkt.Y = h; SetConsoleCursorPosition(GetStdHandle(STDOUTPUTHANDLE), punkt); }

Computer, IT, programmieren, Cplusplus, snake, Spieleprogrammierung

Meistgelesene Fragen zum Thema Cplusplus