007
17.12.2005, 00:06 Uhr
Leopard
|
ok Leute ! es tut mir leid!!
der Code mit Fehlern:
C++: |
#include <iostream> #include <stdlib.h> #include <time.h> #include <string.h> #define N_KEYS 12 #define KEY_MAX_WIDTH 20 #define FAILS_ALLOWED 7 using namespace std;
int main () { int CHOICE; int englisch =1; int deutsch =2; cout << "Geben Sie (1) fuer Englisch oder (2) fuer Deutsch\n" ; cin >> CHOICE; //Fehler 1: 20 expected primary-expression before "int" //Fehler2: 20 expected `;' before "int" switch (CHOICE) { case 1 : int Englisch () { char input; int valid; int fails = FAILS_ALLOWED; unsigned int discoverd = 0; unsigned n; char possiblekeys[KEY_MAX_WIDTH][N_KEYS]; srand ( time (NULL) ); int value = rand()%N_KEYS; strcpy (key, possiblekeys [value]); for (n=0; n<strlen (key); n++) outstring [n]='-'; outstring [n]='\0'; do { cout << "\n Discover the secret key; " << outstring << "\n"; cout << "Enter a letter (You may fail " << fails << " times): "; cin >> input; cin.ignore (100,'\n'); valid = CheckLetter (input); if (valid!=0) discoverd+=valid; else fails --; } while (discoverd < strlen (key) && fails >0); if (discoverd == strlen(key)) cout << " CORRECT! "; cout << "Key was \'" << key << "\'.\n";
return Englisch; // Fehler3: 58 a function-definition is not allowed here before '{' token //Fehler4: 58 expected `,' or `;' before '{' token } int CheckLetter (char letter) { unsigned int n; int found=0; for (n=0; n<strlen (key); n++) if (key [n]==letter && outstring [n]=='-') { found++; outstring [n]=key[n]; } return found; } break; //Fehler5: 73 expected primary-expression before "int" //Fehler6: 73 expected `;' before "int"
case 2: int Deutsch () { char input; int valid; int fails = FAILS_ALLOWED; unsigned int discoverd = 0; unsigned n; char possiblekeys[KEY_MAX_WIDTH][N_KEYS]; srand ( time (NULL) ); int value = rand()%N_KEYS; strcpy (key, possiblekeys [value]); for (n=0; n<strlen (key); n++) outstring [n]='-'; outstring [n]='\0'; do { cout << "\n Discover the secret key; " << outstring << "\n"; cout << "Enter a letter (You may fail " << fails << " times): "; cin >> input; cin.ignore (100,'\n'); valid = CheckLetter (input); if (valid!=0) discoverd+=valid; else fails --; } while (discoverd < strlen (key) && fails >0); if (discoverd == strlen(key)) cout << " CORRECT! "; cout << "Key was \'" << key << "\'.\n";
return Deutsch; //Fehler 7: 112 a function-definition is not allowed here before '{' token //Fehler 8: 112 expected `,' or `;' before '{' token } int CheckLetter (char letter) { unsigned int n; int found=0; for (n=0; n<strlen (key); n++) if (key [n]==letter && outstring [n]=='-') { found++; outstring [n]=key[n]; }
//Fehler9: 123 expected `}' at end of input //Fehler 10: 123 expected `}' at end of input return found; } break;
|
Gruß |