| dagreat45 (12) | |
|
I'm creating a hangman game and I need help as to where I need the players to have an option of seven guesses before game is over can you please help #include <iostream> #include <cmath> #include <iomanip> #include <stdio.h> using namespace std; void oneplayer() { cout << "hello"; } void twoplayer(int &n, int position[5]) { char letter='a'; int cap,i; n=1; cap = 12; for(i=0;i<=cap;i++) { cin >> letter; letter = toupper(letter); if (letter != '.') { position[i]=letter; n++; } else i = cap; } } /*void letterFreq(int freq[]) { char letter; //this while loop allows the user to enter characters and it distinguishes them //individually increasing the value assigned to that letter in the freq array while (letter != '.') { letter = getchar(); letter=toupper(letter); freq[letter]++; } }*/ void twoplayerIO() { cout << "\nPlayer 1 please enter a word without player 2 watching"; char guess; int position[91]; int i, n,wrongGuess; wrongGuess=0; char letter,sentence; //this part goes throught the alphabet because 'A' starts at value of 65 for (i=65; i<91; i++) position[i] = 0; cout << "\nType in your word and enter a period when done.\n"; //this below calls up to the function where the word is recieved twoplayer(n,&position[letter]); for (i = 0; i < n-1; i++) if (position[i]!=0) cout << position[i] << " "; cout << "\n\nits your turn player 2\n" << "enter your first guess.\n" << ":"; cin >> guess; guess = toupper(guess); for (int r = 0; r < n-1; r++) { if (position[r] == guess) { cout << "correct guess"; // graphics where letter would show up break; } else { cout << guess << " is not a letter in the word\n"; wrongGuess++; break; } } } int main() { cout << "Would you like to play a game of hangman Y/N?"; char selection; cin >> selection; //sends the selection to upper case so that lower or upper case can be used and work selection = toupper(selection); cout << endl << endl; while (selection == 'Y') { cout << "1 player or 2 players? \nEnter '1' for 1 or '2' for 2"; int players; cin >> players; if (players == 1) oneplayer(); else if (players == 2) twoplayerIO(); else break; cout << "\nWould you like to play again Y/N 'F'\n"; cin >> selection; selection = toupper(selection); cout << "\n\n"; } while (selection!='a'&&selection!='A'&&selection!='b'&&selection!='B'&&selection!='c'&&selection!='C'&&selection!='d'&&selection!='D') { cout << "Program terminated"; return 0; } } | |
|
|
|
| fafner (221) | |
|
Please use < code > tags around your source code, makes it much more readable :) Secondly, what specifically is the problem? | |
|
|
|