Jump to content

 I have all my functions down, I hope lol So now, I want to check each guess the user enters against the computers seeded random guess after each time the user inputs a guess. Right now, my output is asking for all 5 guesses, and then says Sorry your card is not a match and starts the process all over again, not displaying my displaycards func or display esp func. Any input is much appreciated.

 

I am not allowed to use global variables, the only time I can use arrays is to declare them, otherwise it must be a pointer.  This is the program:

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

 

 

 

This is my code:

#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 userSelect[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18};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();	cout<<"\n";		   	GenerateCorrectCards (generatedCards);//generates the computers cards	for ( i=0; i<5; i++){         *(user + i) = GetGuess();                            CheckMatch (i,generatedCards);                  int currentGuess = GetGuess();        //check if currentGuess is a duplicate before updating user array//if not duplicate, check if it matches computer handbool match = CheckMatch (i, generatedCards);          } cout<<"Player's Choice "<< "   " << "Computer's Choice "<<"\n";     cout<<"*******************************************"<<"\n";    for (i=0; i < 5; i++)     {                      DisplayCards((user+i),generatedCards);        }DisplayESP(i);			//         for (char Z = 'Q' ; Z == 'Q' || Z == 'q';  ){//	//	cout<<"Do you want to play another round?Enter q 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;				//mod for the deck of 18        if (successfulSelections==0) {            *(generatedCards)=selectedInt;        }         for (int i=0;i<successfulSelections;i++) {			//checking for dup            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;  	  	  	  }    }    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 *user, int *GeneratedCorrectCards)    	{    	//DisplayCards is passed the computer’s and the player’s card arrays. //It displays the two sets of cards side by side, by color and shape, not by integer! Has no cin's.////Hint:  Use the card mapping array to look up the integer and get the string representing the card.switch (*(user))	{		case 0:			cout << "red circle"<<endl;			break;		case 1:			cout<< "red square"<<endl;			break;		case 2:			cout << "red triangle" <<endl;			break;		case 3:			cout << "blue circle" <<endl;			break;		case 4:			cout << "blue square" <<endl;			break;		case 5:			cout << "blue triangle" <<endl;			break;		case 6:			cout << "yellow circle"<<endl;			break;		case 7:			cout << "yellow square" <<endl;			break;		case 8:			cout << "yellow triangle" <<endl;			break;		case 9:			cout << "purple circle" <<endl;			break;		case 10:			cout << "purple square" <<endl;			break;		case 11:			cout << "purple triangle" <<endl;			break;		case 12:			cout << "orange circle" <<endl;			break;		case 13:			cout << "orange square"<<endl;			break;		case 14:			cout << "orange triangle" <<endl;			break;		case 15:			cout << "green circle" <<endl;			break;		case 16:			cout << "green square" <<endl;			break;		case 17:			cout << "green triangle" <<endl;			break;						}}    		    void DisplayESP (int i) {switch (i){case 0:	if(i==0)	cout<<"Level 1: Don't ever go to the casino's!";	break;case 1:		if(i==1 || 2)		cout<<"Level 2: Some ESP, slot machines may be best.";		break;case 2:			if (i==3||4)			cout<<"Level 3: Lots of ESP.  Go play the Powerball!";			break;case 3:			if (i==5)			cout<<"You are a psychic! You must go to the casinos and become rich!";			break;}//	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!”					}//DisplayESP is passed the number of matches.  It displays the appropriate ESP Level message. Has no cin's.//		    		        	    
Link to comment
https://linustechtips.com/topic/266389-function-help-c/
Share on other sites

Link to post
Share on other sites

I'll just help you fix one part for now. That should help you continue towards finishing your program.

 

In GetGuess, the userSelect string is never set to anything so none of the comparisons are working in the if statements.

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; // userSelect isn't assigned// I assume you wanteduserSelect = combo;

Second, your function GetGuess doesn't return on all code paths. It should return a default value for an invalid guess. If not strange things may happen.

// simply add this to the end of GetGuessreturn -1; // you can use any number you want to represent an invalid choice. I just choose -1

When you hit a return statement it'll end the function so there's no reason to have the for loop inside GetGuess unless you're letting them try again if they don't guess a valid option. In that case, you should print a message to the user.

if (userSelect == "red circle")    return 1;// ...else    cout << "Invalid guess." << "\n";

Also, since you're limiting their number of tries with the for statement, consider adding another message when they've ran out of tries.

int GetGuess() {    // ...    for (int i = 0; i < 5; i++) {        //...    }    cout << "Too many invalid guesses." << "\n";    return -1;}
Link to comment
https://linustechtips.com/topic/266389-function-help-c/#findComment-3622415
Share on other sites

Link to post
Share on other sites

Ohh man lmao Thats how I know I have been staring at this code for far too long with no assigning userselect.  That fixes my checkmatch func. 

 

I just ran it, got no matches at all.  My out put is this:

 

I guessed green circle, purple circle red circle blue circle and orange circle.

 

None of them matched.

 

Under players choice it shows:

 

green square

orange square

red square

blue square

purple square

 

Then proceeds to tell me I have level 2 ESP with no matches. Hmmm...

 

Edit: I ran it again, had one match of orange triangle

 

The players choice had all different combos than what I selected, and did not have my match in there.  There must be something wrong with my switch statement for displaycards?

Link to comment
https://linustechtips.com/topic/266389-function-help-c/#findComment-3623418
Share on other sites

Link to post
Share on other sites

It looks like what you have should print out all elements of user correctly (assuming you didn't make a mistake in your switch statement).

for (i = 0; i < 5; i++) {    DisplayCards((user + i), generatedCards);}

However, based on the description in the comments, DisplayCards doesn't look finished to me.

//DisplayCards is passed the computer’s and the player’s card arrays. //It displays the two sets of cards side by side, by color and shape, not by integer! Has no cin's.////Hint:  Use the card mapping array to look up the integer and get the string representing the card.

You aren't using GeneratedCorrectCards at all in the function.

 

It also sounds like you're supposed to use the deck array to get the names for both user and GeneratedCorrectCards instead of hard coding them in like you're doing in the switch statement.

Link to comment
https://linustechtips.com/topic/266389-function-help-c/#findComment-3623862
Share on other sites

Link to post
Share on other sites

Hmm but by passing generatedCards it should be, ideally, passing the cards the computer generated into my display cards func, and user is my array for the users guesses.

 

I turned this into a global:

 

std::string  CARDS[19]={"nothing","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"};

 

With the hint she gave, I must have to use this... but gah I'm so confused.

Link to comment
https://linustechtips.com/topic/266389-function-help-c/#findComment-3626688
Share on other sites

Link to post
Share on other sites

ESP isnt the only one, so is display cards lol I'm in desperation mode, I have until midnight and my mind is going numb already looking at this code for 3 hours today.  I'm still a beginner, if that is not obvious enough lol

Yeah, the DisplayESP function is buggy.

switch (i) {    case 0:        if (i == 0) // not needed because i == 0 when it enters here in the switch            cout << "...";        break;    case 1:        if (i == 1 || 2) // this is always true because i == 1 when it enters here and also 2 is always true            cout << "...";        break;    case 2:        if (i == 3 || 4) // this will always be true, i will never be 3, because it's 2 to get here, but 4 is always true            cout << "...";        break;    case 3:        if (i == 5) // this can never be true because i == 3 when it enters here            cout << "...";        break;}

First while this is technically a valid statement that will compile, I doubt it's what you want.

i == 1 || 2// this does not check if i is equal to 1 or 2// it checks if i == 1 OR if 2 is true// you want to do it like thisi == 1 || i == 2

And don't use both switch statements and if statements together. Use one or the other like this

// with if statementif (i == 0)    cout << "...";else if (i == 1 || i == 2)    cout << "...";else if (i == 3 || i == 4)    cout << "...";else if (i == 5)    cout << "...";// with switch statementswitch (i) {    case 0:        cout << "...";        break;    case 1:    case 2:        cout << "...";        break;    case 3:    case 4:        cout << "...";        break;    case 5:        cout << "...";        break;}

In switch statements, if a break isn't included in a case, it will continue executing the next case. So that's why you can have an empty case 1 above case 2 to replicate i == 1 || i == 2 and the same goes for case 3 and case 4. If i == 1, it'll fall through to run the code under case 2.

Link to comment
https://linustechtips.com/topic/266389-function-help-c/#findComment-3627568
Share on other sites

Link to post
Share on other sites

Hmm but by passing generatedCards it should be, ideally, passing the cards the computer generated into my display cards func, and user is my array for the users guesses.

 

I turned this into a global:

std::string  CARDS[19]={"nothing","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"};

With the hint she gave, I must have to use this... but gah I'm so confused.

 

Passing GeneratedCorrectCards in to DisplayCards makes it available, but what I'm saying is that you aren't using it inside the function. In your first post, it only shows 1 switch case inside DisplayCards and that uses the user parameter.

 

Also in your first post you said that you weren't allowed to use global variables. So maybe add it in as another parameter if you're allowed.

// Based on reading the comment, I'm not sure if the function needs to bevoid DisplayCards(int *user, int *GeneratedCorrectCards) {// or if this is allowed so that you can use your deck arrayvoid DisplayCards(int *user, int *GeneratedCorrectCards, const char **deck) {

Also, you don't really need a new array CARDS, because you have deck already. But be careful about adding "nothing" to the beginning of the deck array. That may break other things since then "nothing" can probably be a generated guess by the computer. You're better off just adding or subtracting 1 to the index like so

*(deck + i - 1)// or*(deck + i + 1)// depending on what you need to get the right selection// I believe you need the first one (with the minus 1) however I added them both just as an example
Link to comment
https://linustechtips.com/topic/266389-function-help-c/#findComment-3627685
Share on other sites

Link to post
Share on other sites

Thank you so much lol I did not even realize what a dumb mistake that is.  It is functioning better, but still buggy.  In esp, I passed it theuser instead.  I had two matches and it displayed level 3 esp. My display cards doesn't print out anything after passing generatecorrectcards.  This is the code I currently have, dont mind main, im trying to get a user option to quit lol...

 

#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);std::string  CARDS[19]={"nothing","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"};     int main(){        int generatedCards[5];    int user[5];    int theuser;    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();    cout<<"\n";               GenerateCorrectCards (generatedCards);//generates the computers cards    for ( i=0; i<5; i++){             *(user + i) = theuser=GetGuess();       //  cout<<"playerarray (in main) "<<*(user+i)<<endl;       CheckMatch (i,generatedCards);     //  int currentGuess = GetGuess();//      do{//       if (currentGuess==GetGuess())//       cout<<"You've entered a duplicate card. Please try again.";//       //    //   }while(i<5);                                  ////check if currentGuess is a duplicate before updating user array//////if not duplicate, check if it matches computer hand//bool match = CheckMatch (i, generatedCards);continue;          } cout<<"Player's Choice "<< "   " << "Computer's Choice "<<"\n";     cout<<"*******************************************"<<"\n";  //  for (i=0; i < 5; i++)                            DisplayCards((user+i),(generatedCards));DisplayESP(theuser);    for (char y = 'Y' ; y == 'Y' || y == 'y';  ){    cout<<"\nWould you like to play another round?Y/N\n";cin>>y;if (y=='Y' || 'y'){    int generatedCards[5];    int user[5];    int theuser;    int i;            srand ( time(NULL) );//Seeds the random generator once at the beginning            DisplayInstructions();    cout<<"\n";               GenerateCorrectCards (generatedCards);//generates the computers cards    for ( i=0; i<5; i++){             *(user + i) = theuser=GetGuess();       //  cout<<"playerarray (in main) "<<*(user+i)<<endl;       CheckMatch (i,generatedCards);                                   ////check if currentGuess is a duplicate before updating user array//////if not duplicate, check if it matches computer hand//bool match = CheckMatch (i, generatedCards);continue;          } cout<<"Player's Choice "<< "   " << "Computer's Choice "<<"\n";     cout<<"*******************************************"<<"\n";  //  for (i=0; i < 5; i++)                            DisplayCards((user+i),(generatedCards));DisplayESP(theuser);}else if(y=='N' || 'n')return 0;}}                            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;                //mod for the deck of 18        if (successfulSelections==0) {            *(generatedCards)=selectedInt;        }         for (int i=0;i<successfulSelections;i++) {            //checking for dup            if (*(generatedCards+i)==selectedInt) {                alreadySelect=1;                break;            } else {                alreadySelect=0;                *(generatedCards+successfulSelections)=selectedInt;            }        }        if (alreadySelect==0) {            successfulSelections++;        }    }}                int GetGuess ( ){    {std::string to_lower( std::string str ); // make everything lower case        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;userSelect=combo;          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;      //       for (int i=0;i<5;i++) {        //      int alreadySelect;                                                     //checking for dup//            if (userSelect==combo) {//                alreadySelect=1;//                cout<<"You've entered a duplicate. Please try again.";//                //            } else {//                alreadySelect=0;////          }      cout<<"Too many invalid guesses.";      return -1;              }}       bool  CheckMatch (int theuser, int *generatedCards)    {                for (int i=0;i<5;i++) {        if (*(generatedCards+i)==theuser) {            cout << "Your card matches!" << "\n";            i++;            return true;                       }    }    cout << "Sorry, your card does not match." << "\n";    return false;}        void DisplayCards (int *CARDS, int *GenerateCorrectCards)        {        //DisplayCards is passed the computer’s and the player’s card arrays.//It displays the two sets of cards side by side, by color and shape, not by integer! Has no cin's.////Hint:  Use the card mapping array to look up the integer and get the string representing the card.switch (*(CARDS))    {        case 1:            cout << "red circle"<<endl;            break;        case 2:            cout<< "red square"<<endl;            break;        case 3:            cout << "red triangle" <<endl;            break;        case 4:            cout << "blue circle" <<endl;            break;        case 5:            cout << "blue square" <<endl;            break;        case 6:            cout << "blue triangle" <<endl;            break;        case 7:            cout << "yellow circle"<<endl;            break;        case 8:            cout << "yellow square" <<endl;            break;        case 9:            cout << "yellow triangle" <<endl;            break;        case 10:            cout << "purple circle" <<endl;            break;        case 11:            cout << "purple square" <<endl;            break;        case 12:            cout << "purple triangle" <<endl;            break;        case 13:            cout << "orange circle" <<endl;            break;        case 14:            cout << "orange square"<<endl;            break;        case 15:            cout << "orange triangle" <<endl;            break;        case 16:            cout << "green circle" <<endl;            break;        case 17:            cout << "green square" <<endl;            break;        case 18:            cout << "green triangle" <<endl;            break;                        }}                void DisplayESP (int theuser) {if (theuser == 0)    cout << "Level 1: Don't ever go to the casino!\n";else if (theuser == 1 || theuser == 2)    cout << "Level 2: Some ESP, slot machines may be best.\n";else if (theuser == 3 || theuser == 4)    cout << "Level 3: Lots of ESP.  Go play the Powerball!\n";else if (theuser == 5)    cout << "You are a psychic! You must go to the casinos and become rich!\n";                    //switch(theuser){//////case 0://    if(theuser==0)//    cout<<"Level 1: Don't ever go to the casino's!";//    break;//case 1://        if(theuser==1 || 2)//        cout<<"Level 2: Some ESP, slot machines may be best.";//        break;//case 2://            if (theuser==3||4)//            cout<<"Level 3: Lots of ESP.  Go play the Powerball!";//            break;//case 3://            if (theuser==5)//            cout<<"You are a psychic! You must go to the casinos and become rich!";//            break;}//    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!”                    //DisplayESP is passed the number of matches.  It displays the appropriate ESP Level message. Has no cin's.//                                    
Link to comment
https://linustechtips.com/topic/266389-function-help-c/#findComment-3627791
Share on other sites

Link to post
Share on other sites

Also, if you are using the std namespace, then why are you using it for the string class and objects?

 

 

I have to use strings, its a requirement.  I'm trying to figure out what's wrong with DisplayESP.  Any hints?  I'm not asking for you to write the code for me, but by the sounds of it you know exactly whats wrong lol

 

He means that because you have this

using namespace std;

You don't have to use std:: in front of things.

// thisstd::string to_lower( std::string str);// can become thisstring to_lower(string str);// and thisstd::string color,shape,combo,userSelect;//can become thisstring color,shape,combo,userSelect;

You can also use std::endl instead of "\n" if you want.

cout << "text" << endl;// endl will end the line so it can replace "\n"
Link to comment
https://linustechtips.com/topic/266389-function-help-c/#findComment-3627793
Share on other sites

Link to post
Share on other sites

With no matches, it doesn't display ESP at all. Should I be passing i instead?

Doesn't matter what you name it. They are both integers either way. Just make sure that when you are calling DisplayESP, it's given the right value.

 

If DisplayESP isn't printing the right value, then theuser isn't holding the right value.

 

You can always have it print out the invalid value at the end of your if statement in the DisplayESP function for debugging purposes.

else    cout << "The invalid value was " << theuser << endl;
Link to comment
https://linustechtips.com/topic/266389-function-help-c/#findComment-3627860
Share on other sites

Link to post
Share on other sites

I completely missed your post about the deck.  So would you recommend leaving deck as it is and in main decrementing it with i?

Doesn't matter so long as you make something work :P

 

If "nothing" (ie: zero) can't be chosen in GenerateCorrectCards, then you're probably fine. Just don't use "nothing"/0 anywhere it's not supposed to be.

Link to comment
https://linustechtips.com/topic/266389-function-help-c/#findComment-3628066
Share on other sites

Link to post
Share on other sites

OOOOH heres something interesting.  No matches, and with the debugging idea you had, it says the invalid value is 13. What in the...

 

 

This was with passing theuser.

 

Passing i was giving me the psychic every time. I am lost in space rn

 

Edit: two matches, in invalid value is 16

Link to comment
https://linustechtips.com/topic/266389-function-help-c/#findComment-3628235
Share on other sites

Link to post
Share on other sites

You're using the users guess in DisplayESP. A guess can be 0 - 17 (or 1 - 18 with "nothing" in there). You want to add up the correct matches (ie: when CheckMatch returns true) and then put that number in DisplayESP

 

I was able to get a little something working without too much trouble. Didn't need to change GenerateCorrectCardsCheckMatch or DisplayESP at all so they should all be working. I think it's mostly DisplayCards and main that needs work.

 

GetGuess looks like it works right although I would change it's return value to 0 instead of -1 after too many invalid guesses. That way it matches with "nothing" in your const array. Also I expect your teacher wants you to get the integer from your constant array instead of hard coding the switch statement.
Link to comment
https://linustechtips.com/topic/266389-function-help-c/#findComment-3628340
Share on other sites

Link to post
Share on other sites

madknight you've been more than enough help, but i am extremely desperate at this point lol What am I doing wrong with displaycards????  I know I need to get the integer... I just don't know how.

 

Should I have some kind of accumulator in my bool func to pass to esp?

Link to comment
https://linustechtips.com/topic/266389-function-help-c/#findComment-3629411
Share on other sites

Link to post
Share on other sites

Here's a hint for what I did as a test function

void DisplayCards(int *usersGuesses, int *GenerateCorrectCards, const char ** deck) {    cout << "Users Guess" << "\t\t\t" << "Generated Cards" << endl;    for (int i = 0; i < 5; ++i) {        // Get the names of the choices from the deck        string nameOfUsersChoice = ...;        string nameOfGeneratedCard = ...;        // print the names side by side        cout << nameOfUsersChoice << "\t\t\t" << nameOfGeneratedCard << endl;    }}

I think you might need to sort them before printing them but that shouldn't be hard once you get the names.

 

Here's my sample output from that function once you fill in the blanks for the two strings.

Users Guess			Generated Cardspurple circle			blue trianglered circle			green trianglegreen square			green squarered triangle			blue squaregreen triangle			orange square
Link to comment
https://linustechtips.com/topic/266389-function-help-c/#findComment-3629985
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×