C++ :: Tic Tac Toe Console Game - If Statement Does Not Make Correct Decision
Feb 18, 2015
I recently wrote a "Tic Tac Toe" console game, and i seem to have a problem in my winning conditions, as when it checks if the player won (should have won) it doesn't take the appropriate action.
The winning conditions are in CoreLogic.cpp
here's the code, might not be the most pretty and clean code ever but it works for me.
there are more files i just didn't feel the need to include them all since the problem is only within CoreLogic.cpp and possibly in main.cpp
pos1-pos9 have been declared in the UserInterface.cpp and are being used to determine the correct decision to do within CoreLogic.cpp
Nothing happens when you win at this point it just exits the program.
Okay so I thought I had this assignment completed properly last week. Last night I found a bug while playing the game.why won't the game end when the player guesses the correct number? The game allows you to finish using the max number of guesses even though you already guessed the correct number.
My code is supposed to read a five to four digit code of a resistor from a file and determine the resistor's nominal, lower and upper tolerance values. I have inputted my file's first resistor code as a string so I could run tests on it but the problem that occurs is that a get the wrong values from my switch-case statements. I have put printfs after the function call to see what the values were and they turned out wrong. If I could get my return values to be right then I could be on my way coding.
#include<stdlib.h> #include<stdio.h> double bandNum(char x); // function prototype that will read the resistor value for the first, second and possibly third band double bandMult(char x); // function prototype that multiplies the resistor by some value of 10 double bandTol(char x); // function prototype that the tolerance of the resistor is multiplied by
cout << "You've made 3 mistakes ! Game is now over !" << endl; cout << "You had " << correctGuesses << " correct guesses before the game was over" << endl; this info into a text file...
example of a guessing game code...
#include <iostream> #include <time.h> using namespace std; int main() {
cout << "This is a very simple number guessing game. Each time you will be given a number of the range 0-10." << endl; cout << "The objective of the game is to guess whether the next number is going to be higher or not. As simple as that." << endl;
#include <iostream> #include <windows.h> using namespace System; using namespace std; int refreshDisplay(int , int); const char wHole = '@';
[code]....
count <<" The oblective of the game is for the player to move around a 2 dimensional playing field and capture the star withought falling into a black hole or walking off the edge of the playing field. The controls are W = up S= down A=Left D=Right" <<endl; how implement 3 black hole X characters and 2 wormhole characters on field @ and a star *. all these char has to be randomly generated.
I made a rock paper scissors game in c++. How to make it better, and what i can do differently
#include <iostream> #include <string> using namespace std;
int checkConvertInput(string signs[], int wins, int draws, int losses); void calculateWinner(int playerSign, string signs[], int &wins, int &draws, int &losses); void endResult(int wins, int draws, int losses);
The program i am trying to make is for practice of using switch. the idea is the user enters a number and the program will print a day of the week corresponding to said number.
the statement is not complete with all cases yet, but i dont want to write all of it until i am sure of it being correct.
errors when compiling (gcc) are as follows
1 warning and 3 errors generated. Robins-MacBook-Air:array2 RDenton$ gcc array2.c array2.c:26:9: warning: format string is not a string literal (potentially insecure) [-Wformat-security] printf(a[uservalue]);
I'm making a program that would run 24/7 and that could be run on multiple computers that are all running Windows (the program would be in the startup folder of the computer).
So I'm searching for 2 functions, one that would check if the program has been already launched on this computer and another one that would do a save every 24 hours. but for the second one I don't know what I should do because I think that a loop with sleep() would take too much power for the cpu
I'm making a simple single-player game. Now, assume I've made the game, how would I go about making it available to play on LAN? (I'm not really bothered about making it playable across the world with people not on the same wi-fi)
So, any way that I could get started or any libraries/APIs ....
I'm using Windows 8.1 and I'd like my game to be playable on other Windows OSs (7 and Vista if possible)
I'm just playing around with C++ and I'm trying to make a sort of virtual pet game. I know its not the best looking code but I'm trying. But as of right now I'm trying to be able to animate the game a little . For example , if a user decides to "pet" their "pet" I want the pets mouth to open from '_' to ^o^ like this:
() () ('_') -> () () (^o^) and switch back and forth.
Here's my code:
#include <iostream> #include <cstring> using namespace std; void Greeting()
Lets say that I try and make a BASIC game with c++, how do I make the animations/graphics for the game (i.e the characters ) Do I need a specific complier/ide (I am using visual studio)
when it comes to programming. I was trying to make a simple letter guessing game where the user has 6 chances to guess the letter V. The command prompt works fine until the user enters 'y' to play. It repeats my HIGH & LOW statements twice before letting me guess again. It's all a mess.
So I've just been messing with enet trying to figure out how to make a server and client for a game. I'm having problems whenever the server receives something from a client. For now I'm just trying to send it to all the clients for them to draw the other player, but for some reason whenever I try to an error message comes up saying a breakpoint has been triggered. I don't know why it is happening. This is the code that is giving me problems.
for (unsigned int i = 0; i < peers.size(); i++) enet_peer_send(peers[0], 0, event.packet);
I am trying to solve a MIP problem using C with Cplex linker. I need to find min value of two decision variables, as far as i know, i should write as a constraint because they are decision variables. "if" statement does not work for decision variables. here is some part of my model in C.
Code:
void TSPMIP(int Scenario, int Agency) { int i,j; double tmpDouble;
I'm working with a game editor program, where the player can create their own maps. Right know I'm working with collisions, and since it's unpredictable where the player place the objects like trees, houses and cars...etc have I an idea with making a rectangle selection tool. Where the player can drag a collision box around the object, so the sprite stops when it hits the box. The problem is that I dont know how to make a tool like that. so my question is how do I create a tool like that (see picture under for more information)?
btw I'm using the SDL framework
here is a picture that illustrate the tool I want to create: [URL] ....
I am starting a turn based battle (similar to pokemon) app. How could i make this and make it cross platform. Also is it possible to make it access gps and allow other devices with the same app communicate with each other?
I have done things on the command line but i never made anything with images so i dont even know where to start for this app.
I'm trying to implement a decision tree that gets doubles as input (in this sample code just random numbers) and returns a boolean value. At the nodes, I'd like to use various operators that can have different input and return types. I've implemented an abstract base class for the nodes and I'm deriving the specific nodes from it. In the code below, I've included only a few derived classes. Building the tree (randomly) is no problem. However, I'm looking for a clever way to evaluate the tree. I think that uncommenting the lines in bold print would in principle do it. However, this is not possible because "value" is not a member of the base class. The type of "value" is different in the derived classes, so I cannot simply declare it in the base class.
"Node.h" #pragma once class NodeBase{ public: NodeBase* Child_1; NodeBase* Child_2; virtual void evaluate() = 0;
if (Choice == 2) { cout << "" << endl << "You follow the light to the end of the hallway, you find your self in a room" << endl << "with natural light coming from a hole in the ceiling." << endl << "" << endl << "You hear the door you just came through, slam behind you!" << endl << "" << endl << "There are three possible directions." << endl << "" << endl << "Do you:" << endl << "" << endl << "1) Go forward" << endl << "" << endl << "2) Go left" << endl
[Code] .....
Ignore the if (Choice == 2) at the beginning, that's linked to some previous code.
I want to make the player go back to the first bit of text but i'm not sure how to do this if they keep choosing to go back and forth from one location.
I first thought of doing it by just putting the text back in after they have chosen the option, but I can't do this infinite times.
I am trying to make a basic Snake game using the command window and screen refreshes. So far I have a board, snake, food, and no walls. Basically I have it so the snake moves like the traditional snake in the game, when it eats the food once it grows. However when it eats the food a second time the game crashes. I think I have narrowed the issue down to the grow array that I have (below) but I am not sure if the issue could be a result of something else.
Grow Array
cord growArray (cord *p_values, int *size) { *size = *size + 1; cord *p_new_values = new cord[ *size ];
my a book or website where I can make a transition from console programming to GUI programming. I'm totally confused about this. I know how to program in console and can make a whole program based on console. I also know the OPP programming, but it's clear that nobody uses console programming anymore.