i was asked to do game that are similar with mastermind game.
but i have an error that my program said there is calling of non function.
here is my code
hope there is solution for this error.
tq.
#include<iostream.h>
#include<conio.h>
//-----void main()
void main()
{
void Header();
Header();
void GenRand();
GenRand();
getch();
}
//-----end void main()
//-----void Header()
//display the header
void Header()
{
cout << "===========Welcome to the Game==========" << endl;
cout << "This is a game of logic." << endl;
cout << "The goal is to guess the correct four symbols combination by using your previous guesses as clues." << endl;
cout << "Everytime you guess,you will be told how close to the goal you are." << endl;
cout << "The first number says how many symbols are in the right place." << endl;
cout << "The second number says how many right symbols are in the wrong place." << endl;
cout << "To guess, enter four symbols choosen from the set of five symbols." << endl;
cout << "The five symbols are % # $ * &" << endl;
cout << "A sample guess would look like this: % * $ #" << endl;
cout << "You have 6 tries to complete the goal." << endl;
cout << "All the best!" << endl << endl;
}
//-----end void header()
//-----void GenRand()
//generate random numbers
void GenRand()
{
srand((unsigned)time(NULL));
int rand[4];
for(int i = 0 ; i <4 ; i++)
rand[i] = rand() % 5;
while (rand[1] == rand[0])
rand[1] = rand() % 5;
while (rand[2] == rand[0] || rand[2] == rand[1])
rand[2] = rand() % 5;
while (rand[3] == rand[0] || rand[3] == rand[1] || rand[3] == rand[2])
rand[3] = rand() % 5;
void RandSym(int[4]);
RandSym(rand);
}
//-----end void GenRand()
//----void RandSym()
void RandSym(int rand[4])
//associate the random numbers with symbols
{
char code[4];
for (int i = 0 ; i <4 ; i++)
{
//conversion of rand1 to a symbol from a number
if(rand[i] == 0) code[i] = '%';
else if (rand[i] == 1) code[i] = '#';
else if (rand[i] == 2) code[i] = '$';
else if (rand[i] == 3) code[i] = '&';
else if (rand[i] == 4) code[i] = '*';
else;
}
for (int i=0 ; i<4 ; i++)
cout <<""<<code[i]<<"";
void Play(char [4]);
Play(code);
}
//-----end void RandSym()
//-----void Check()
void Check (char code[4], char guess1, char guess2, char guess3, char guess4, int &right,int &wrong)
//calculating right wrong
{
if (guess1==code[0] && guess2==code[1] && guess3==code[2] && guess4==code[3])
goto out;
//calculating for correct symbol and position and correct symbol but wrong position
else {
if (guess1 == code[0])
right++;
else
if ((guess1==code[1])||(guess1==code[2])||(guess1==code[3]))
wrong++;
else;
if (guess2 == code[1])
right++;
else
if ((guess2==code[0])||(guess2==code[2])||(guess2==code[3]))
wrong++;
else;
if(guess3 == code[2])
right++;
else
if ((guess3==code[0])||(guess3==code[1])||(guess3==code[3]))
wrong++;
else;
if (guess4 == code[3])
right++;
else
if((guess4==code[0])||(guess4==code[1])||(guess4==code[2]))
wrong++;
else; }
out:
}
//-----end void Check()
//-----void Play()
void Play(char code[4])
{
void Check (char [4], char, char , char , char , int&, int&);
char guess1, guess2, guess3, guess4;
for(int i=1;i<=6;i++)
{
int right=0;
int wrong=0;
cout<<"\n\nTRIAL :"<<i<<endl;
cout<< "Enter your guess with four symbols (%,#,$,&):";
cin >> guess1 >> guess2 >> guess3 >> guess4;
Check(code,guess1, guess2, guess3, guess4,right, wrong);
if (guess1==code[0] && guess2==code[1] && guess3==code[2] && guess4==code[3])
{
cout << " ********** " << endl;
cout << "===============*YOU WIN!*===============" << endl;
cout << " ********** " << endl << endl;
goto end;}
else
{
cout << " Right symbol & right position:" << right << endl;
cout << " Right symbol & wrong position:" << wrong << endl;
}
}
cout << "\nSORRY! Answer was: " <<endl;
for (int i = 0 ; i <4 ; i++)
cout << ""<<code[i]<<"" ;
end:
}