473,405 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

i am having an error with int main() and also with my code reading the case's properl

it is just that i have this source code for a game with menu, but when i run it it does not work, if i run the game separated from the menu it works, when i run the menu alone it also works fine, but when i run them togheter it does not.



#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <stdio.h>
bool salida= false;


using namespace std;
char square[10] = {'o','1','2','3','4','5','6','7','8','9'};
int checkwin();
void board();
int player = 1,i,choice;
char mark;

int opcion=0,x=0;

void board();
bool menu=false;
int main()
{
while( menu==false)
{
printf(" BIENVENIDOS AL GATO-LOKO\n");
printf("1 ... Jugar 'gato' nivel luz .\n");
printf("2 ... Jugar 'gato' nivel karen.\n");
printf("3 ... Creditos \n");
printf("4 ... Salir \n");
scanf("%d",& opcion);
switch(opcion)
{
case 1:
{

printf(" el juego comenzara en \n");
printf("\n\t\t\t3\n\n");
Sleep (500);
printf("\n\t\t\t2\n\n");
Sleep (500);
printf("\n\t\t\t1\n\n");
Sleep (500);
printf("\t\1");
Sleep(700);
printf("\t\2");
Sleep(700);
printf("\t\3");
Sleep(700);
printf("\t\4");
Sleep(700);
printf("\t\5");
Sleep(700);
printf("\t\6");
Sleep(700);
system("cls");
printf("GATO-LOKO");





do
{
board();
player=(player%2)?1:2;

printf("jugador , introduce numero", player );
cin >> choice;

mark=(player == 1) ? 'X' : 'O';

if (choice == 1 && square[1] == '1')

square[1] = mark;
else if (choice == 2 && square[2] == '2')

square[2] = mark;
else if (choice == 3 && square[3] == '3')

square[3] = mark;
else if (choice == 4 && square[4] == '4')

square[4] = mark;
else if (choice == 5 && square[5] == '5')

square[5] = mark;
else if (choice == 6 && square[6] == '6')

square[6] = mark;
else if (choice == 7 && square[7] == '7')

square[7] = mark;
else if (choice == 8 && square[8] == '8')

square[8] = mark;
else if (choice == 9 && square[9] == '9')

square[9] = mark;
else
{
cout<<"movimiento no valido ";

player--;
cin.ignore();
cin.get();
}
i=checkwin();

player++;
}while(i==-1);
board();
if(i==1)

printf("ajugador gano",player);
else
cout<<"==>\aempate";

cin.ignore();
cin.get();
return 0;
}




{
if (square[1] == square[2] && square[2] == square[3])

return 1;
else if (square[4] == square[5] && square[5] == square[6])

return 1;
else if (square[7] == square[8] && square[8] == square[9])

return 1;
else if (square[1] == square[4] && square[4] == square[7])

return 1;
else if (square[2] == square[5] && square[5] == square[8])

return 1;
else if (square[3] == square[6] && square[6] == square[9])

return 1;
else if (square[1] == square[5] && square[5] == square[9])

return 1;
else if (square[3] == square[5] && square[5] == square[7])

return 1;
else if (square[1] != '1' && square[2] != '2' && square[3] != '3'
&& square[4] != '4' && square[5] != '5' && square[6] != '6'
&& square[7] != '7' && square[8] != '8' && square[9] != '9')

return 0;
else
return -1;
}





{
system("cls");
cout << "\n\n\tGATO LOKO\n\n";

cout << "JUGADOR 1 (X) - JUAGADOR 2 (O)" << endl << endl;
cout << endl;

cout << " | | " << endl;
cout << " " << square[1] << " | " << square[2] << " | " << square[3] << endl;

cout << "_____|_____|_____" << endl;
cout << " | | " << endl;

cout << " " << square[4] << " | " << square[5] << " | " << square[6] << endl;

cout << "_____|_____|_____" << endl;
cout << " | | " << endl;

cout << " " << square[7] << " | " << square[8] << " | " << square[9] << endl;

cout << " | | " << endl << endl;


}

break;















}

break;

case 2:

{
printf(" el juego comenzara en \n");
printf("\n\t\t\t3\n\n");
Sleep (500);
printf("\n\t\t\t2\n\n");
Sleep (500);
printf("\n\t\t\t1\n\n");
Sleep (500);
system("cls");
printf("GATO-LOKO");
printf("\t\1");
Sleep(700);
printf("\t\2");
Sleep(700);
printf("\t\3");
Sleep(700);
printf("\t\4");
Sleep(700);
printf("\t\5");
Sleep(700);
printf("\t\6\n\n\n");
Sleep(700);


}

break;

case 3:

{



printf(" \n\t\t efectos especiales: LUZ, KARREN, JUAN \n");
Sleep(300);
system("cls");







}

break;

case 4:
{
printf("bye bye");


int player = 1,i,choice;

char mark;
do
{
board();
player=(player%2)?1:2;

printf("jugador , introduce numero", player );
cin >> choice;

mark=(player == 1) ? 'X' : 'O';

if (choice == 1 && square[1] == '1')

square[1] = mark;
else if (choice == 2 && square[2] == '2')

square[2] = mark;
else if (choice == 3 && square[3] == '3')

square[3] = mark;
else if (choice == 4 && square[4] == '4')

square[4] = mark;
else if (choice == 5 && square[5] == '5')

square[5] = mark;
else if (choice == 6 && square[6] == '6')

square[6] = mark;
else if (choice == 7 && square[7] == '7')

square[7] = mark;
else if (choice == 8 && square[8] == '8')

square[8] = mark;
else if (choice == 9 && square[9] == '9')

square[9] = mark;
else
{
cout<<"movimiento no valido ";

player--;
cin.ignore();
cin.get();
}
i=checkwin();

player++;
}while(i==-1);
board();
if(i==1)

printf("ajugador gano",player);
else
cout<<"==>\aempate";

cin.ignore();
cin.get();
return 0;
}




{
if (square[1] == square[2] && square[2] == square[3])

return 1;
else if (square[4] == square[5] && square[5] == square[6])

return 1;
else if (square[7] == square[8] && square[8] == square[9])

return 1;
else if (square[1] == square[4] && square[4] == square[7])

return 1;
else if (square[2] == square[5] && square[5] == square[8])

return 1;
else if (square[3] == square[6] && square[6] == square[9])

return 1;
else if (square[1] == square[5] && square[5] == square[9])

return 1;
else if (square[3] == square[5] && square[5] == square[7])

return 1;
else if (square[1] != '1' && square[2] != '2' && square[3] != '3'
&& square[4] != '4' && square[5] != '5' && square[6] != '6'
&& square[7] != '7' && square[8] != '8' && square[9] != '9')

return 0;
else
return -1;
}





{
system("cls");
cout << "\n\n\tGATO LOKO\n\n";

cout << "JUGADOR 1 (X) - JUAGADOR 2 (O)" << endl << endl;
cout << endl;

cout << " | | " << endl;
cout << " " << square[1] << " | " << square[2] << " | " << square[3] << endl;

cout << "_____|_____|_____" << endl;
cout << " | | " << endl;

cout << " " << square[4] << " | " << square[5] << " | " << square[6] << endl;

cout << "_____|_____|_____" << endl;
cout << " | | " << endl;

cout << " " << square[7] << " | " << square[8] << " | " << square[9] << endl;

cout << " | | " << endl << endl;


}







salida=true;

}



break;

default:
{
system ("cls");
printf("Opcion incorrecta intentar de nuevo...\n");

system("PAUSE");












}
}
Jun 10 '14 #1
1 1162
weaknessforcats
9,208 Expert Mod 8TB
Step through the code using your debugger.

Since you are using no functions stepping through the code in main() is your best choice.
Jun 11 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Roland Hall | last post by:
This question crosses between this group and IIS, so I have included both. I'm referencing a MSFT document: Creating Custom ASP Error Pages:...
4
by: sabads | last post by:
Hello all: I'm a student learning procedure-oriented programming(use C). I want to read some smart programs that perform important aspects of structure programming.so I'm eager to obtain some...
1
by: joe10001 | last post by:
Hi all, I just installed CRELoaded (oscommerce fork) on my server and all work fine except that I have a little message at the bottom of the main page : Fatal error: main() : Security alert:...
8
by: boki_pfc | last post by:
Hi Everybody, I am looking for an advice on following: I have that "pleasure" of reading C++ codes that have been written by person(s) that have not attended the same C++ classes that I did or...
13
by: ishakarthika | last post by:
how can i compare the a private variable of a class and a value in the column of a text file. there is a syntax error in my code while comparing. senario is i am getting bus details like busno,...
0
by: vagueante | last post by:
Hi, I have a windows service that i connecto to a iSeries Dataqueue, i can write and read from it. The purpose of this service it's to keep reading the dataqueue and when it has some data i run...
9
whatelyb
by: whatelyb | last post by:
I am having trouble related to the attached coding. I am trying to make the object "flight1pic" change depending on what is selected in the drop down menus "airline1" and "aircraft1". My...
1
by: manikandanc | last post by:
if i tying to insert the values in access table not showing any error but also not saving the values in table. plz,Help.
1
by: game2d | last post by:
I am using libgdx and getting a error. I am not sure what this error means and how can I fix this? error: - Line 41: No source code is available for type java.awt.geom.Line2D.Float; did you...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.