Ich schreibe einen Code, um ein einfaches textbasiertes Blackjack-Spiel in C++ zu erstellen. Ich fange gerade an, aber ich stieß sofort auf ein Problem. Hier ist der Code, den ich bis jetzt habe, beachten Sie, dass es NICHT beabsichtigt ist, vollständig zu sein oder sogar noch zu laufen. Ja, ich weiß, es ist extrem chaotisch und ineffizient, ich bin in meiner ersten C++ - Klasse aller Zeiten.Kennung nicht gefunden Fehler?
Mein Problem ist, dass ich "Bezeichner nicht gefunden" bekomme, wenn mein Code rekursive Funktionen aufruft (DealingHandler und EndProgram). Ja, ich weiß, eine Funktion speziell zum Beenden des Programms ist in diesem Programm völlig nutzlos, aber ich weiß nicht, wie ich das Programm plötzlich ohne etwas in der Art beenden soll.
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std; const int maxScore = 21; //immutable upper limit
//string nameInput; - Idea for later.
int HandVal, DealerHandVal, Aceone, val, aceVal;
char HitStay;
string DealerHand, currenthand; //Strings to output the cards (4 5 for example)
int numAces, numTwo, numThree, numFour, numFive, numSix, numSeven, numEight, numNine, numTen, numJack, numQueen, numKing; //Inefficient way of making sure it doesn't give five twos out, however unlikely that may be.
int main() {
cout << "Welcome to our C++ BlackJack Program." << endl;
cout << "Please press enter to begin the game." << endl;
system("PAUSE");//Bad. Still easiest for a beginning C++ class.
currenthand = "";
numAces = 4;
numTwo = 4;
numThree = 4;
numFour = 4;
numFive = 4;
numSix = 4;
numSeven = 4;
numEight = 4;
numNine = 4;
numTen = 4;
numJack = 4;
numQueen = 4;
numKing = 4;
int i = 2;
{
DealingHandler(i);
cout << DealerHand;
cout << "Press H to hit or S to stay." << endl;
cin >> HitStay;
switch (HitStay){
case 'H':
DealingHandler(1);
break;
case 'h':
DealingHandler(1);
break;
case 's':
EndProgram();
break;
case 'S':
EndProgram();
break;
default:
cout << "Invalid entry.";
break;
}
}
system("PAUSE");
}
int DealingHandler(int HowManyDealed) {
for (int x = 0; x <= HowManyDealed; x++) {
val = rand() % 13;
switch (val) {
case '1':
cout << "A";
cout << "Press One to set this Ace equal to one. Press Two to set it equal to eleven. This cannot be changed, so choose wisely!" << endl;
cin >> aceVal;
if (aceVal = 1) {
Aceone = 1;
currenthand += " 1";
cout << currenthand << endl;
HandVal += 1;
}
if (aceVal = 2) {
Aceone = 11;
currenthand += " 11";
cout << currenthand << endl;
HandVal += 11;
}
numAces = numAces - 1;
case '2':
currenthand += " 2";
cout << currenthand << endl;
HandVal += 3;
numTwo -= 1;
break;
case '3':
currenthand += " 3";
cout << currenthand << endl;
HandVal += 3;
numThree -= 1;
break;
case '4':
currenthand += " 4";
cout << currenthand << endl;
HandVal += 4;
numFour -= 1;
break;
case '5':
currenthand += " 5";
cout << currenthand << endl;
HandVal += 5;
numFive -= 1;
break;
case '6':
currenthand += " 6";
cout << currenthand << endl;
HandVal += 6;
numSix -= 1;
break;
case '7':
currenthand += " 7";
cout << currenthand << endl;
HandVal += 7;
numSeven -= 1;
break;
case '8':
currenthand += " 8";
cout << currenthand << endl;
HandVal += 8;
numEight -= 1;
break;
case '9':
currenthand += " 9";
cout << currenthand << endl;
HandVal += 9;
numNine -= 1;
break;
case '10':
currenthand += " 10";
cout << currenthand << endl;
HandVal += 10;
numTen -= 1;
break;
case '11':
currenthand += " J";
cout << currenthand << endl;
HandVal += 10;
numJack -= 1;
break;
case '12':
currenthand += " Q";
cout << currenthand << endl;
HandVal += 10;
numQueen -= 1;
break;
case '13':
currenthand += " K";
cout << currenthand << endl;
HandVal += 10;
numKing -= 1;
break;
}
if (HandVal < 21) {
cout << "Busted!" << endl;
EndProgram();
}
}
return HandVal;
}
void EndProgram()
{
cout << "I hope you had fun with my game!";
system("PAUSE");
}
Vielen Dank im Voraus für Ihre Hilfe.
Sie benötigen einen Prototyp für 'int DealingHandler hinzufügen (int) 'und' void EndProgram() 'über' int main() ' – drescherjm
Wenn Sie' std :: toupper' oder 'std :: tolower' vor der Anweisung 'switch' verwenden, können Sie die Anzahl der Fälle um die Hälfte reduzieren . –