Free Essay

Tic Tac Oe

In:

Submitted By jacob00
Words 1048
Pages 5
Computer Programming
Computer Programming
TIC TAC TOE PROJECT
TIC TAC TOE PROJECT
Flor Garcia
FINAL EXAM
Flor Garcia
FINAL EXAM
2015
2015

DEFINE THE PROBLEM:
Write a Tic Tac Toe program that inputs the player’s names and then asks if you want to play again. It displays a score board at the end of the game.

OUTLINE THE SOLUTION: INPUT | PROCESSING | OUTPUT | Name of Player 1 | Names of Both players is inputted | Score board of who won, lost or any draws | Name of Player 2 | Player 1 makes the first move by choosing a number in the box then [X] will replace the chosen number | | Numbers on each box | Player 2 makes the second move by choosing a number in the box then [O] will replace the chosen number | | | If either of the players win, they receive a point in the score board | | | If it is a draw, the score board will display it | |

DEVELOP AN ALGORITHM: 1. Insert name of player 1 [X] 2. Insert name of player 2 [O] 3. Players choose the number of the box they want to input their letter in. 4. Once then choose the number they inputted their designated letter will replaced the number in the box 5. These steps are repeated as it is each player’s turn 6. The game will end until someone wins or it becomes a draw 7. The Score board will be displayed at the end
TEST THE ALGORITHM: 1. Name of Player 1: Flor 2. Name of Player 2: Karla 3. Flor chooses number 3 and is replaced by [X] 4. Karla chooses number 9 and is replaced by [O] 5. Each player goes until someone wins 6. Karla wins and the score board is displayed showing her as the winner.

CODE THE ALGORYTHM:
#include <iostream>
#include <string> void boardGame(); void next(); bool end(); char name();

char turn; bool draw = false; char board[3][3] = {{'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}}; string playerName1 = " "; string playerName2 = " "; bool ans; int main()
{
cout << " Player 1 name is: " << endl; cin >> playerName1; cout << " Player 2 name is: " << endl; cin >> playerName2; cout << "Lets Play a Tic Tac Toe Game! \n"; cout << playerName1 << " is X --- " << playerName2 << " is O\n"; turn = 'X';

while (!end()) { boardGame(); next(); end(); }

if (turn == 'O' && !draw) { boardGame(); cout << endl << endl << playerName1 << " X Wins \n" << endl; cout << "------------------------------------------" << endl; cout << "| " << playerName1 << " | 1 |" << endl; cout << "|____________________________|___________|" << endl; cout << "| " << playerName2 << " | 0 |" << endl; cout << "|____________________________|___________|" << endl; cout << "| draw | 0 |" << endl; cout << "|____________________________|___________|" << endl; } else if (turn == 'X' && !draw) { boardGame(); cout << endl << endl << playerName2 << " O Wins \n" << endl; cout << "------------------------------------------" << endl; cout << "| " << playerName1 << " | 0 |" << endl; cout << "|____________________________|___________|" << endl; cout << "| " << playerName2 << " | 1 |" << endl; cout << "|____________________________|___________|" << endl; cout << "| draw | 0 |" << endl; cout << "|____________________________|___________|" << endl; } else { boardGame(); cout << endl << endl << "It's a draw \n" << endl; cout << "------------------------------------------" << endl; cout << " | " << playerName1 << " | 0 |" << endl; cout << "|____________________________|___________|" << endl; cout << "| " << playerName2 << " | 0 |" << endl; cout << "|____________________________|___________|" << endl; cout << "| draw | 1 |" << endl; cout << "|____________________________|___________|" << endl; }
}

void boardGame()
{
cout << "---------------------" << endl << endl; cout << " | | " << endl; cout << " " << board[0][0] << " | " << board[0][1] << " | " << board[0][2] << endl; cout << "_____|_____|_____" << endl; cout << " | | " << endl; cout << " " << board[1][0] << " | " << board[1][1] << " | " << board[1][2] << endl; cout << "_____|_____|_____" << endl; cout << " | | " << endl; cout << " " << board[2][0] << " | " << board[2][1] << " | " << board[2][2] << endl; cout << " | | " << endl;
}

void next()
{
int choice; int row = 0, column = 0;

if (turn == 'X') { cout << playerName1 << " X: "; } else if (turn == 'O') { cout << playerName2 << " O: "; } cin >> choice;

switch (choice) { case 1: row = 0; column = 0; break; case 2: row = 0; column = 1; break; case 3: row = 0; column = 2; break; case 4: row = 1; column = 0; break; case 5: row = 1; column = 1; break; case 6: row = 1; column = 2; break; case 7: row = 2; column = 0; break; case 8: row = 2; column = 1; break; case 9: row = 2; column = 2; break; default: cout << "Number can't be used. Please try another number.\n"; next(); }

if (turn == 'X' && board[row][column] != 'X' && board[row][column] != 'O') { board[row][column] = 'X'; turn = 'O'; } else if (turn == 'O' && board[row][column] != 'X' && board[row][column] != 'O') { board[row][column] = 'O'; turn = 'X'; } else { cout << "You can't use that box. Please Try Again .\n"; next(); }

}

bool end()
{
for (int i = 0; i < 3; i++) { if ((board[i][0] == board[i][1] && board[i][1] == board[i][2]) || (board[0][i] == board[1][i] && board[1][i] == board[2][i]) || (board[0][0] == board[1][1] && board[1][1] == board[2][2]) || (board[0][2] == board[1][1] && board[1][1] == board[2][0])) { return true; } }

for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (board[i][j] != 'X' && board[i][j] != 'O') { return false; } } }

draw = true; return true;
}

Similar Documents

Free Essay

Action Research

...Case Study Research Report Christine Y. Harris Grand Canyon University RDG 581 October 12, 2011 Action Research Plan: Effective Interventions for Vocabulary Acquisition in Children of Disadvantaged Backgrounds The Purpose Research suggests that students can be taught phonics skills that are needed to become proficient readers. The use of strategies such as guessing from context, predicting and re-reading may aid, to some extent, with reading comprehension. However, according to Becker (1977), a primary difficulty in developing comprehension in the early years in reading is an inadequate vocabulary. An insufficient vocabulary will have an adverse impact on reading comprehension. E.D.Hirsch states “It is now well accepted that the chief cause of the achievement gaps between socioeconomic groups is a language gap.” The purpose of this research is to determine how explicit instruction using interventions can help close the vocabulary deficits with children from disadvantaged backgrounds The Problem Children of lower socioeconomic backgrounds enter kindergarten with a less extensive vocabulary than those of higher socioeconomic environment. One study showed that three year old children from affluent families had larger vocabularies than children from impoverished families (Hart and Risley, et al 1995). Unfortunately, once the deficit in vocabulary is established, differences in vocabulary knowledge are hard to eliminate. This leads to continued gaps as students...

Words: 7486 - Pages: 30

Free Essay

Sadsf

...Animals Co G eo T oke a i P pyx rze na P Le yro Ne aur is c tta sul u n O ot o a c ci Sc cos em tidtiel cotyrbo atin pes ut cyp a d ea la r lis nar us Tr Wi ell ha om le ut pi ia As In ich lco inia o e po ilan la co G erm oph xina sc roa stic rina s a u r u d Ch esmlaz Ale isia ea miktell ctica m al is iell uri ag hyb olaata Un a a a g de Ca P zionsph au au reg rida e rw lo ulv h ae ran ran ata o s e r H o cy in lv os tia tia H e dia ph ula et po ca B elv lve co a ar icu ra Ba Ba alsa ella lla t lumfulg che m e r e La Re Wy rssi lsammia lac rre nar ns i by dd nn a o ia m un str is a o is r e e r Di inth llom lla ego vulg gna sa ng om y si ne a ta ce lv n ris le yc i Tu T Tya v es s docolosis b u u e v n r Ch T er be be rru ariu ki T ub rap r g r b co s i oir Ch om oir T ube er e aeo ibbo orch sa yc om ube r pa xca dor sum ii Ar e y r n v u th r O s m ce m nif atu m D ob rb e s v agn eru m M Mo D ac otr ili an en at m on na ac cr A act tyle ys da de drifo osu um ro os rth yle lla ac lic rm s s p r a St D por oriuobo lla rho tylo tu is eg La Mo Ar udd ium m trys oxy pal ide la ob sio na thr in ge ha r sp ota s ium de cr o gt p pt obu o o parma spo O botr onia hyro otylu st ra nic se riu rb ys fla pa ma Um eumrrico m e ilia a con gra ga M bil ye rne llips uric oide ns yc ic oc o o ali La aria ast li yea spo lor s Ch ae S Ste ciu sa su ke st li ra no ph no m llia bg sy ke Co th in c a r la m nio ec ctr ybe lbo os br Ce Con s o in p nig sic a Sa ra io po ps a u r a rcin Gr mo spo...

Words: 13456 - Pages: 54

Free Essay

Case Study

...Keele St. Huntington Rd. Ave. Weston R d. Kipling Av e. Pine Valle y nc Woo drive h D Rd. Kersey McCowan Rd. Cook Na p Kennedy Rd. Keele Weston Ve llore Gdns. Brodie Dr. 10 10 Rutherford Rd. 13 85A 10 Rutherford Rd. 85A 85A Fincham Ave. 85A,B 63 360 Rutherford 85+ Rd. Rutherford 107B 86 105 Rutherford 85+ 105 86 R 23 non-Rush 23 86 86 88E 85+ Rd. d. Springh Hillcrest Carrville Rd. Mall 11 Maple Av e. Stone Mason Dr. 85,B Yonge St . hattan Man Avenu e Clarence St. Pearson Ave. Unionville asant Rid ge Av. k ee W. Be ave r Cr Bayview Buc Allstate Pkwy. Dufferin Point Dr. Hunter's Isling ton Ave. East Valhalla Dr. Frontenac Ple E. Nor th R ivermed e Rd. Morning Sta rD 15 23+ 23+ 12 14 23+ Eagle Edgeley Bl vd. Millway Ave. Rd. Forest Dr. Chate laine Dr. Jane Creditston e Ave. Weston Warden McCowan Rd. Pr ofe ss ors La ke Pk wy. Keele Pine Valle y Dr. Whitmore Rd. Grove R d. Atkinson i nster Yonge St . Hood Rd. Ave. Hend erso n Ave. Martin Ne w Bayview Dr St . Peter Kaiser Gt. Win Mountcastle Gt. term ute Blvd Birc . hm Rd. 32 ms illia W y. Pkw 19 19 92 al ntr Ce Par k Founders Blvd. Cr. le 12 Hillda Rossdean Petrolia Claire Ave. Rd. Hull Dr. Signet ...

Words: 9349 - Pages: 38

Free Essay

Bush

...FAMILY OF SECRETS The Bush Dynasty, America’s Invisible Government, and the Hidden History of the Last Fifty Years RUSS BAKER Contents Foreword by James Moore 1. How Did Bush Happen? 2. Poppy’s Secret 3. Viva Zapata 4. Where Was Poppy? 5. Oswald’s Friend 6. The Hit 7. After Camelot 8. Wings for W. 9. The Nixonian Bushes 10. Downing Nixon, Part I: The Setup 11. Downing Nixon, Part II: The Execution 12. In from the Cold 13. Poppy’s Proxy and the Saudis 14. Poppy’s Web 15. The Handoff 16. The Quacking Duck 17. Playing Hardball 18. Meet the Help 19. The Conversion 20. The Skeleton in W.’s Closet 21. Shock and . . . Oil? 22. Deflection for Reelection 23. Domestic Disturbance 24. Conclusion Afterword Author’s Note Acknowledgments Notes Foreword When a governor or any state official seeks elective national office, his (or her) reputation and what the country knows about the candidate’s background is initially determined by the work of local and regional media. Generally, those journalists do a competent job of reporting on the prospect’s record. In the case of Governor George W. Bush, Texas reporters had written numerous stories about his failed businesses in the oil patch, the dubious land grab and questionable funding behind a new stadium for Bush’s baseball team, the Texas Rangers, and his various political contradictions and hypocrisies while serving in Austin. I was one of those Texas journalists. I spent about a decade...

Words: 249168 - Pages: 997

Free Essay

There Once Was a Young Wild Pony

...eo ep eq er es et eu ev ew ex ey ez fa fb fc fd fe ff fg fh fi fj fk fl fm fn fo fp fq fr fs ft fu fv fw fx fy fz ga gb gc gd ge gf gg gh gi gj gk gl gm gn go gp gq gr gs gt gu gv gw gx gy gz ha hb hc hd he hf hg hh hi hj hk hl hm hn ho hp hq hr hs ht hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy iz ja jb jc jd je jf jg jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw jx jy jz ka kb kc kd ke kf kg kh ki kj kk kl km kn ko kp kq kr ks kt ku kv kw kx ky kz la lb lc ld le lf lg lh li lj lk ll lm ln lo lp lq lr ls lt lu lv lw lx ly lz ma mb mc md me mf mg mh mi mj mk ml mm mn mo mp mq mr ms mt mu mv mw mx my mz na nb nc nd ne nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu nv nw nx ny nz oa ob oc od oe of og oh oi oj ok ol om on oo op oq or os ot ou ov ow ox oy oz pa pb pc pd pe pf pg ph pi pj pk pl pm pn po pp pq pr ps pt pu pv pw px py pz qa qb qc qd qe qf qg qh qi qj qk ql qm qn qo qp qq qr qs qt qu qv qw qx qy qz ra rb rc rd re rf rg rh ri rj rk rl rm rn ro rp rq rr rs rt ru rv rw rx ry rz sa sb sc sd se sf sg sh si sj sk sl sm sn so sp sq sr ss st su sv sw sx sy sz ta tb tc td te tf tg th ti tj tk tl tm tn to tp tq tr ts tt tu tv tw tx ty tz ua ub uc ud ue uf ug uh ui uj uk ul um un uo up uq ur us ut uu uv uw ux uy uz va vb vc vd ve vf vg vh vi vj vk vl vm vn vo vp vq vr vs vt vu vv vw vx vy vz wa wb wc wd we wf wg wh wi wj wk wl wm wn wo wp wq wr ws wt wu wv ww wx wy wz xa xb xc xd xe xf xg xh xi xj xk xl xm xn xo xp xq xr...

Words: 29642 - Pages: 119

Free Essay

Deseo

...Shayla Black Dominada por el deseo ~1 ~ Shayla Black Dominada por el deseo SHAYLA BLACK DOMINADA POR EL DESEO ~2 ~ Shayla Black Dominada por el deseo ÍNDICE ARGUMENTO ............................................................................. 4 Capítulo 1.................................................................................. 5 Capítulo 2................................................................................ 23 Capítulo 3................................................................................ 46 Capítulo 4................................................................................ 59 Capítulo 5................................................................................ 78 Capítulo 6.............................................................................. 103 Capítulo 7.............................................................................. 125 Capítulo 8.............................................................................. 156 Capítulo 9.............................................................................. 178 Capítulo 10............................................................................ 201 Capítulo 11............................................................................ 214 Capítulo 12............................................................................ 235 Capítulo 13............................................................................

Words: 123901 - Pages: 496

Free Essay

English Vinglish

...Copyediting & Proofreading FOR DUMmIES by Suzanne Gilad ‰ Copyediting & Proofreading For Dummies® Published by Wiley Publishing, Inc. 111 River St. Hoboken, NJ 07030-5774 www.wiley.com Copyright © 2007 by Wiley Publishing, Inc., Indianapolis, Indiana Published by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400, fax 978-646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, 317-572-3447, fax 317-572-4355, or online at http://www.wiley.com/go/permissions. Trademarks: Wiley, the Wiley Publishing logo, For Dummies, the Dummies Man logo, A Reference for the Rest of Us!, The Dummies Way, Dummies Daily, The Fun and Easy Way, Dummies.com, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc., and/or its affiliates in the United States and other countries, and may not be used without written permission. All...

Words: 125743 - Pages: 503