Question
how can i calculate the scores of the two players in this game #include #include using namespace std; int main(){ cout < < ******Welcome to
how can i calculate the scores of the two players in this game
#include #include
using namespace std;
int main(){
cout << "******Welcome to Game of Scrabbles****** "; cout << "Two player game.Each player will get the set of characters (A-Z).Every player "; cout << " will enter a word and corresponding characters will be removed from the set (A..Z) "; cout << " .Game will continue till all the characters are used up and at the end all the words "; cout << " will be output on the screen ";
string p1_set = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRST"; string p2_set = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRST";
string p1_new = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRST"; string p2_new = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRST";
string p1_words[100]; string p2_words[100]; string word; char c; int found;
int count1 = 0; int count2 = 0; while(p1_new.length() > 0 || p2_new.length() > 0){
if (p1_new.length() > 0){ cout << " Player1 set of characters:" << p1_new << endl << endl;; cout << " Player1: Enter a word:"; cin >> word; p1_words[count1] = word; p1_new = ""; for (int i = 0; i found = 0; for(int j=0; j c = word[j]; if (word[j] >= 'a' && word[j] <= 'z'){ c = word[j] - 32; } if (c == p1_set[i]){ found = 1; word[j] = ' '; break; } } if (found == 0) p1_new = p1_new + p1_set[i]; } count1++; p1_set = p1_new; }
if (p2_new.length() > 0){ cout << " Player2 set of characters:" << p2_new << endl; cout << " Player2: Enter a word:"; cin >> word; p2_words[count2] = word; p2_new = ""; for (int i = 0; i found = 0; for(int j=0; j c = word[j]; if (word[j] >= 'a' && word[j] <= 'z'){ c = word[j] - 32; } if (c == p2_set[i]){ found = 1; word[j] = ' '; break; } } if (found == 0) p2_new = p2_new + p2_set[i]; } count2++; p2_set = p2_new; } } cout << "Player1 words: "; for(int i = 0; i cout << p1_words[i] << endl; } cout << "Player2 words: "; for(int i = 0; i cout << p2_words[i] << endl; }
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started