Tic Tac toe c++ using functions

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 35867 Views - Last Post: 07 October 2007 - 03:30 PM Rate Topic: -----

#1 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Tic Tac toe c++ using functions

Posted 28 September 2005 - 05:15 PM

I am making a tic tac toe program in mrs.robinson's class. and these functions are confusing me. can u help me build this program. This is wat she gave us to work with:

// This function determines if a value is within a range.
// PRE: min <= max and value is defined
// POST: returns true if min <= value <= max, and false
// otherwise
bool ValueInRange(int value, int min, int max);

// This function determines if a row of tic-tac-toe squares is a 
// winning row
// PRE:s1, s2, and s3 are defined
// POST: returns true if a row (horizontal, vertical, or
// diagonal) on a tic-tac-toe board containing [s1, s2, s3], is a
// winning row, and false otherwise.
bool RowIsWinner(char s1, char s2, char s3);

// This function returns the oppenent of the player.
// PRE: player == X or playe = O
// POST: returns the oppenent of player.
char TTTopponent(char player);

// This function gets a valid intger input from the user.
// PRE: User has been prompted to enter an integer representing
// the space they want to play in and min <= max.
// POST: an integer value, i, entered by user is returned, where
// min <= i <= max.
int GetIntInput(int min, int max);

// This function displays one of the horizontal line in a TTT
// board.
// PRE: the cout output marker is at the start of a new line.
// POST: a horizontal line has been drawn on the cout stream.
void DisplayHorizontalLine();

// This function displays one row od a TTT board with sqaures s1,
//s2 and s3
// PRE: the cout output marker is at the start of a new line.
// POST: A row of the TTT board is drawn on the cout stream.
void DisplayOneRow(char s1, char s2, char s3);

Rules
The Rules of Tic-Tac-Toe
*The game board is a three by three square grid of symbols, which is initially empty.
The empty game board in your program should look something like the one shown just below:
 (i couldnt align the | symbols right but they are aligned right above the + symbol).				
				 |	 |
			 ---+---+---		   
				 |	 |			  
			 ---+---+---			   
				 |	 |

Notice that it contains three rows (as in DisplayOneRow) and two horizontal lines (as in DisplayHorizontalLine).
*There are two players, named Player X and Player O.
Player O goes first.
*a player moves by selecting an empty square on the board.
*a symbol representing that player (i.e., an X or an O) is placed on the selected sqaure, and it becomes the other player's turn.
*The game is won if one player gets three symbols in a row (horizontally, vertically, or diagonally).
*The game is a draw if all the squares become occupied, yet no player has won.

well this is the rubric of wat she gave us i hope u can help me do this program TY! :D

Is This A Good Question/Topic? 1

Replies To: Tic Tac toe c++ using functions

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Tic Tac toe c++ using functions

Posted 28 September 2005 - 06:06 PM

Well, the Mrs. Robinson part doesn't mean much, I'm afraid, unless you're referring to an older woman who's seduced you..if so, then kudos on the reference.

As for the program, I'm afraid we don't normally give out straight code for school assignments. You mention that you have been provided with the base code you've shown...can you post what you've attempted so far? If you can demonstrate that you have amde some attempst to complete the assignment, we'd be happy to provide some guidance.
Was This Post Helpful? 0
  • +
  • -

#3 Videege  Icon User is offline

  • rÍvant.toujours
  • member icon

Reputation: 6
  • View blog
  • Posts: 1,413
  • Joined: 25-March 03

Re: Tic Tac toe c++ using functions

Posted 28 September 2005 - 06:19 PM

Amadeus, on Sep 28 2005, 07:03 PM, said:

Well, the Mrs. Robinson part doesn't mean much, I'm afraid, unless you're referring to an older woman who's seduced you..if so, then kudos on the reference.

As for the program, I'm afraid we don't normally give out straight code for school assignments. You mention that you have been provided with the base code you've shown...can you post what you've attempted so far? If you can demonstrate that you have amde some attempst to complete the assignment, we'd be happy to provide some guidance.

rofl, Mrs. Robinson, if I remember correctly, is the intro to comp sci teacher at RRHS.

Try to attempt the problem; if you need some guidance, I believe I have a tic-tac-toe snippet/recursion thing in the code snippets (granted mine deals with AI, that's not part of this assignment).
Was This Post Helpful? 0
  • +
  • -

#4 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Re: Tic Tac toe c++ using functions

Posted 28 September 2005 - 06:41 PM

yea how u know it was at rrhs? lol! i will print wat i got so far on my program tomorrow and show u wat i got so far so u guys can help me
Did u take mrs.robinsons class to?

This post has been edited by KLiT: 28 September 2005 - 06:44 PM

Was This Post Helpful? 0
  • +
  • -

#5 Videege  Icon User is offline

  • rÍvant.toujours
  • member icon

Reputation: 6
  • View blog
  • Posts: 1,413
  • Joined: 25-March 03

Re: Tic Tac toe c++ using functions

Posted 28 September 2005 - 06:52 PM

Definitely show us what you have.

To your other question, I am currently a senior at RRHS, and no, I never took Mrs. Robinson's class (thank God?).
Was This Post Helpful? 0
  • +
  • -

#6 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Re: Tic Tac toe c++ using functions

Posted 28 September 2005 - 07:21 PM

wuts ur name? i prolly know who u r....
Was This Post Helpful? 0
  • +
  • -

#7 Videege  Icon User is offline

  • rÍvant.toujours
  • member icon

Reputation: 6
  • View blog
  • Posts: 1,413
  • Joined: 25-March 03

Re: Tic Tac toe c++ using functions

Posted 28 September 2005 - 07:37 PM

The names Barron, Josh Barron - ask Hanosh if you don't know.

/end personal conversation
Was This Post Helpful? 0
  • +
  • -

#8 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Re: Tic Tac toe c++ using functions

Posted 29 September 2005 - 07:16 AM

This is wat i have so far:
#include <iostream.h>							   
													 
bool ValueInRange(int value, int min, int max); 
bool RowIsWinner(char s1, char s2, char s3);
char TTToppnent(char player); 
int GetIntInput(int min, int max);
void DisplayHorizontalLine(); 
void DisplayOneRow (char s1, char s2, char s3);

 int main()
{
	 
	 
	 int num, value;
	 char Player1[20], Player2[20];

		 
	 	 
	 cout<< "Tic Tac Toe 1.0\n";
	 cout<< "\nPlease enter your name: ";
	 cin.get(Player1, 20);
	 cin.ignore(80, '\n');
	
	 cout<< "\nPlease enter oppenents name: ";
	 cin.get(Player2, 20);
 	 cin.ignore(80, '\n');

	 
	
	do 
	{
	   
		
	}while (num != true);
	{


	return 0;
}
	

bool ValueInRange(int value, int min, int max)
{
	if((value>=min)&&(value<=max))
		return true;
	else
		return false;
}

int GetIntInput(int min, int max)
{
	int choice;
	bool good;

	do
	{
		cout<<"Please choose a location to move to ";
		cin >> choice;
		good = ValueInRange(choice, min, max);
	}while(!good);

	return choice;
}


i mostly need help on writing the functions in code like the one above.
i would appreciate if u would help me write the functions.

This post has been edited by Dark_Nexus: 07 October 2007 - 03:29 PM

Was This Post Helpful? 0
  • +
  • -

#9 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Tic Tac toe c++ using functions

Posted 29 September 2005 - 07:29 AM

Well, the diplay horizontal line function seems pretty straight forward...I would think that something like the following would suffice:
void DisplayHorizontalLine()
{
   cout<<"---+---+---"<<endl;
}


As for some of the others
char TTToppnent(char player)//this is supposed to return the opponent
{
  char retOpponent = 'X';
  if(player=='X')
     retOpponent = 'O';
  return retOpponent;
}


Give some of the others a quick try based on the descriptions...see what you get!
Was This Post Helpful? 0
  • +
  • -

#10 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Re: Tic Tac toe c++ using functions

Posted 29 September 2005 - 07:59 AM

HEy dawg thx for wat u gave me now i can finish the rest of the tic-tac-toe program! :D

<(o.O<) (>O.o)> now i wanna dance!
Was This Post Helpful? 0
  • +
  • -

#11 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Tic Tac toe c++ using functions

Posted 29 September 2005 - 08:13 AM

Please note correction to opponent function above.
Was This Post Helpful? 0
  • +
  • -

#12 Videege  Icon User is offline

  • rÍvant.toujours
  • member icon

Reputation: 6
  • View blog
  • Posts: 1,413
  • Joined: 25-March 03

Re: Tic Tac toe c++ using functions

Posted 29 September 2005 - 05:04 PM

Once you learn more c++ you might want to go back to this program and try making your tic tac toe functions into a class, its a good exercise.

Also thow in some error checking (mostly checking the cin stream for good input)

This post has been edited by Videege: 29 September 2005 - 05:05 PM

Was This Post Helpful? 1

#13 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Re: Tic Tac toe c++ using functions

Posted 04 October 2005 - 06:44 AM

Im bak with some help. Ok im done with the program except with one thing. that 1 thing is getting the cat game to work in the tic tac toe. couple classmates and my teacher trying to find out how to get cats game to work. So if u guys could help us or explain how to do it we would apperciate it! :D



Can someone plz reply? :sleepy:

This post has been edited by KLiT: 04 October 2005 - 07:28 AM

Was This Post Helpful? 0
  • +
  • -

#14 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Tic Tac toe c++ using functions

Posted 04 October 2005 - 07:27 AM

What do you mean by 'cat game'?
Was This Post Helpful? 0
  • +
  • -

#15 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Re: Tic Tac toe c++ using functions

Posted 04 October 2005 - 07:32 AM

lol u know when u play tic tac toe and no one wins its called a cat game...-.- or if u still dont know wat a cat game is it could be called a draw

This post has been edited by KLiT: 04 October 2005 - 07:37 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2