C++ Simple Program not running properly

This program is giving me a dodgy output, its meant to be a board of numbers. Thank you.

#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int firstplayerinput;
int secondplayerinput;
char firstplayermark = 'x';
char secondplayermark = 'O';
char squareone = 1;
char squaretwo = 2;
char squarethree =3;
char squarefour =4;
char squarefive = 5;
char squaresix = 6;
char squareseven = 7;
char squareeight = 8;
char squarenine = 9;
string Continue;
bool bGamenotover = true;
int main(){
cout << "Hello, welcome to Tic Tac Toe, enter a value (values from 1-9 and row-based e.g. first row: 1-3 second row: 4-6 third row: 7-9) on the board to place an X (if you are player 1 who always starts first) or an O (if you are player twowho always starts second)" << endl << "Would you like to start playing? .yes. .no.";
cin >> Continue;
while(bGamenotover) {



cout << "First player turn. " << endl;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl;
cout << "First player turn. Enter value: " << endl;
cin >> firstplayerinput;
if(firstplayerinput == 1) {
squareone = firstplayermark;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl;}
else if(firstplayerinput == 2) {squaretwo = firstplayermark;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl;
}
else if(firstplayerinput == 3) {
squarethree = firstplayermark;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl;
}
else if(firstplayerinput == 4) {
squarefour = firstplayermark;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl;}
else if(firstplayerinput == 5) {
squarefive = firstplayermark;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl; }
else if(firstplayerinput == 6) {
squaresix = firstplayermark;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl;}
else if(firstplayerinput == 7) {
squareseven = firstplayermark;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl;}
else if(firstplayerinput == 8) {squareeight = firstplayermark;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl;}
else if(firstplayerinput == 9) {
squarenine = firstplayermark;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl;}
cout << "Second player turn. Enter value: ";
cin >> secondplayermark;
if(secondplayerinput == 1) {squareone = secondplayermark;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl;}
else if(secondplayerinput == 2) {squaretwo = secondplayermark;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl;}
else if(secondplayerinput == 3) {squarethree= secondplayermark;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl;}
else if(secondplayerinput == 3) {squarethree = secondplayermark;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl;}
else if(secondplayerinput == 4) {squarefour = secondplayermark;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl;}
else if(secondplayerinput == 5) {squarefive = secondplayermark;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl;}
else if(secondplayerinput == 6) {squaresix = secondplayermark;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl;}
else if(secondplayerinput == 7) {squareseven = secondplayermark;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl;}
else if(secondplayerinput == 8) {squareeight = secondplayermark;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl;}
else if(secondplayerinput == 9) {squarenine = secondplayermark;
cout << squareone << " | " << squaretwo << " | " << squarethree << endl;
cout << squarefour << " | " << squarefive << " | " << squaresix << endl;
cout << squareseven << " | " << squareeight << " | " << squarenine << endl;}
if(squareone != 1 && squaretwo != 2 && squarethree != 3 && squarefour != 4, squarefive != 5, squaresix != 6, squareseven != 7, squareeight != 8, squarenine != 9) {cout << "Board is full" << endl;
bGamenotover = false;}
if(firstplayermark == squareone && squaretwo && squarethree){
cout << "First Player Wins" << endl;
bGamenotover = false;
return 0;}
else if (firstplayermark == squarefour && squarefive && squaresix){
cout << "First Player Wins" << endl;
bGamenotover = false;
return 0;}
else if (firstplayermark == squareseven && squareeight && squarenine){
cout << "First Player Wins" << endl;
bGamenotover = false;
return 0;}
else if (firstplayermark == squareone && squarefive && squarenine){
cout << "First Player Wins" << endl;
bGamenotover = false;
return 0;}
else if (firstplayermark == squarethree && squarefive && squareseven){
cout << "First Player Wins" << endl;
bGamenotover = false;
return 0;}
if(secondplayermark == squareone && squaretwo && squarethree){
cout << "Second Player Wins" << endl;
bGamenotover = false;
return 0;}
else if (secondplayermark == squarefour && squarefive && squaresix){
cout << "Second Player Wins" << endl;
bGamenotover = false;
return 0;}
else if (secondplayermark == squareseven && squareeight && squarenine){
cout << "Second Player Wins" << endl;
bGamenotover = false;
return 0;}
else if (secondplayermark == squareone && squarefive && squarenine){
cout << "Second Player Wins" << endl;
bGamenotover = false;
return 0;}
else if (secondplayermark == squarethree && squarefive && squareseven){
cout << "Second Player Wins" << endl;
bGamenotover = false;
return 0;}
else { cout << "No-one has won yet";
}
}
}


Im sorry I couldn't elaborate on my description how the word limit wouldnt let me! Any help is greatly appreciated, Im new to C++ and I am in an awkward position now where I cant really progress as Im unable to isolate this problem. It is meant to be a Tic Tac Toe board with the outcome of numbers 1-9, however it seems to be outputting a load of upside down crosses. Im very confused as a previous version worked however it has suddenly messed up when I added a checking system if someone had won including a boolean value. Thank you!
Hi,

Those weird output characters are the chars you tell the program to print.

Look at this:
1
2
char a = 1
cout << a << endl;

You assign the value 1 to the char. This is a "control character", which is unprintable. Note that this is no the same as the char "1", but the character whose numeric value is 1 (look here for the value of chars: http://www.asciitable.com/).

Your program has many things that could be improved, I'll point some of them:

(1)
There is no need to assign the numbers to the "square" variables. Why don't you initialize them with a single space? That would solve your print problem

(2)
You have a lot of sentences like this one:
firstplayermark == squarefour && squarefive && squaresix
This is wrong, you don't want to make a logical operation between the square values. It will always return true, as long as all the variables have some value.
This is what you want:
firstplayermark == squarefour && firstplayermark == squarefive && firstplayermark == squaresix

(3)
The program can be A LOT shorter. Put the commonly used code in a subroutine, and remove duplicated code when possible.
Thank you so much for the help as the char values issue would have been hard to spot without it aswell as the player mark detail. This has not only made my program work, but will greatly aid me in the future!
Topic archived. No new replies allowed.