000
19.12.2005, 16:51 Uhr
Leopard
|
Hallo liebe hilfsbereite Programmierer, Ich hab endlich meinen Code duf die Reihe gekriegt. Allerdings tauch eine kleine Fehlermeldung, von der ich wirklich keine Ahnung habe. Da habe ich an euch gedacht
der Code mit der Fehlermeldung:
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;
//Possible keys. char possiblekeys [N_KEYS][KEY_MAX_WIDTH] = { "mushroom", "pineapple", "neighborhood", "citizen", "programming", "darkness", "fundamental", "encyclopedia", "businessman", "restaurant", "observatory", "civilization" } ;
// This will store the key char key [KEY_MAX_WIDTH];
//This will store the string shown on screen with letters already discovered char outstring [KEY_MAX_WIDTH];
int CheckLetter (char letter);
main () { char input; int valid; int fails = FAILS_ALLOWED; unsigned int discovered = 0; unsigned int n; // Select a key srand (time(NULL)); //Initialize random number generator int value = rand()%N_KEYS; //Get random between 0 and NKEYS-1 strcpy (key, possiblekeys [value]); // Copy key // Set outstring to '-' characters plus terminating null-character for (n=0; n<strlen (key); n++) outstring [n] = '-'; outstring [n]= '\0'; do { // Prompt user cout << "\n Discover the secret key: " << outstring << "\n"; cout << "Enter a letter (You may fail " << fails << " times): "; cin >> input; cin.ignore (100, '\n'); // Check if letter is valid valid = CheckLetter (input); // If it is valid, increase dicovered letters counter. // If not, decrease allowed fails if (valid!=0) discovered+ = valid ; //Die Fehlermeldung lautet: 54 expected primary- // expression before '=' token else fails--; } while (discovered < strlen(key) && fails>0); // The lope ends if key is discovered or fails are exhausted. // Display CORRECT! only if key was discovered. if (discovered == strlen (key)) cout << "CORRECT! "; cout << "Key was '" << key << "'.\n"; return 0; }
// Function that checks if letter is in the key // returns the number of times the letter was found in the key 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; }
|
Ich bitte um Hilfe von hilfsbereiten Programmieren! Danke! |