So i posted a previous thread about mapping, I got that down. This is the background to my assignment:
The rules of ESP are:
There is a deck of 18 cards that looks like this:
Each card has a color and a shape.
There are 3 shapes: CIRCLE, SQUARE, TRIANGLE
There are 6 colors: RED, BLUE, YELLOW, PURPLE, GREEN, ORANGE
For example: one card is BLUE SQUARE
The program allows the player to play as many rounds as they'd like.
The program gives the player the opportunity to quit after each round, by entering 'Q' or 'q'.
One round consists of:
The computer will randomly choose 5 cards from this deck (these are the 'correct' cards).
The player will guess 5 cards by entering a color and a shape for each. (Give them exactly 5 chances to guess in one round (see below for duplicate guesses).)
For each guess, display whether or not it matches one of the 'correct' cards. Cards do not have to be in the same order as the correct cards to win. Display whether or not it is a duplicate guess, which is not allowed.
After the player has made 5 guesses, the round is over, at which point
the program will display that round's information (see below) and ask if they want to play again.
At the end of each round, display the following:
⦁ the five cards the computer selected (correct cards) (color/shape of each card)
⦁ the five cards the player guessed (color/shape of each card)
⦁ the player’s ESP Level (you must have these 4 exact levels, but you can make up your own messages!)
0 matches: “Level 1: No ESP at all!”
1-2 matches: “Level 2: Some ESP, keep working on it!”
3-4 matches: “Level 3: Lots of ESP, try Powerball!”
5 matches: “Level 4: ESP expert! Host a TV show!”
Here are some tricky parts: (Plan to devote a good amount of time to solving these problems.)
⦁ make sure there are no duplicate cards generated for the computer (i.e. no duplicates in 'correct' cards)
⦁ make sure there are no false positives, i.e.
RED CIRCLE should not be a match if the computer chose RED SQUARE and GREEN CIRCLE.
⦁ Do not let the player choose a duplicate card (i.e. one already guessed before in that round). If they choose a duplicate, you must allow them to choose again. (i.e. always 5 non-duplicate guesses.)
⦁ Don’t let the player get duplicate matches for guessing the same correct card several times!
(similar to #3 above)
⦁ Remember that the cards do not have to be in the same order to match.
Now, my problem here is, when I run the program it compiles. It displays the instructions, says enter your card by shape then color. It does that, and just keeps cout Please choose a card..... infinitely when it should be only 5 times, returning whether the card the user chose matches the computers after every guess. What is wrong? BTW, i'm only halfway through the coding btw, I'm just having trouble with why this is happening.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
using namespace std;
void DisplayInstructions ( );
void GenerateCorrectCards (int *);
int GetGuess ( );
bool CheckMatch (int , int *);
void DisplayCards (int *, int *);
void DisplayESP (int);
int main()
{
int generatedCards[5];
int const CARDS =18;
int user[5];
int i;
const char *deck [CARDS]={"red circle","red square","red triangle","blue circle","blue square",
"blue triangle","yellow circle","yellow square","yellow triangle","orange circle",
"orange square" ,"orange triangle","purple circle","purple square",
"purple triangle","green circle","green square","green triangle"};
srand ( time(NULL) );//Seeds the random generator once at the beginning
DisplayInstructions();
GenerateCorrectCards (generatedCards);
for ( i=0; i<*generatedCards; i++){
*(user + i) = GetGuess();
}
bool CheckMatch (int user, int *GenerateCorrectCards);
// for (char Z = 'Q' ; z == 'Q' || z == 'q'; ){
//
// cout<<"Do you want to quit?"
//}
//}
}
void DisplayInstructions()
{
cout << "The computer will generate a deck of 18 cards.\n"
<< "There are 3 shapes: Circle, square, and triangle.\n"
<< "There are 6 colors: Red, blue, yellow, orange, purple, and green.\n"
<< "Pick a shape and then a color.\n"
<< "Do this 5 times and see if your predictions match what the computer picked,\n checking your ESP level!\n";
}
void GenerateCorrectCards(int *generatedCards)
{
int i;
int selectedInt;
int alreadySelect = 0;
int successfulSelections = 0;
while (successfulSelections < 5) {
selectedInt = (rand() % 18) + 1;
if (successfulSelections==0) {
*(generatedCards)=selectedInt;
}
for (int i=0;i<successfulSelections;i++) {
if (*(generatedCards+i)==selectedInt) {
alreadySelect=1;
break;
} else {
alreadySelect=0;
*(generatedCards+successfulSelections)=selectedInt;
}
}
if (alreadySelect==0) {
successfulSelections++;
}
}
}
int GetGuess ( )
{
int const CARDS=18;
std::string deck [CARDS]={"red circle","red square","red triangle","blue circle","blue square",
"blue triangle","yellow circle","yellow square","yellow triangle","orange circle",
"orange square" ,"orange triangle","purple circle","purple square",
"purple triangle","green circle","green square","green triangle"};
std::string to_lower( std::string str ); // make everything lower case
for (int i=0;i<5;i++)
{
std::string color,shape,combo,userSelect;
cout<<"Please choose a card with a color first, and then a shape.";
cin>>color>>shape;
combo= color + " " +shape;
combo=userSelect;
if (userSelect=="red circle")
return 1;
else if (userSelect=="red triangle")
return 2;
else if(userSelect=="red square")
return 3;
else if(userSelect=="blue circle")
return 4;
else if (userSelect=="blue triangle")
return 5;
else if(userSelect=="blue square")
return 6;
else if(userSelect=="yellow circle")
return 7;
else if(userSelect=="yellow triangle")
return 8;
else if(userSelect=="yellow square")
return 9;
else if (userSelect=="orange circle")
return 10;
else if (userSelect=="orange triangle")
return 11;
else if(userSelect=="orange square")
return 12;
else if (userSelect=="purple circle")
return 13;
else if (userSelect=="purple triangle")
return 14;
else if (userSelect=="purple square")
return 15;
else if(userSelect=="green circle")
return 16;
else if ( userSelect=="green triangle")
return 17;
else if (userSelect=="green square")
return 18;
break;
}
}
bool CheckMatch (int user, int *generatedCards)
{
for (int i=0;i<5;i++) {
if (*(generatedCards+i)==user) {
cout << "Your card matches!" << "\n";
return true;
}
}
cout << "Sorry, your card does not match." << "\n";
return false;
}
void DisplayCards (int *, int *)
{
}
|