-
Student
Help
Can you help me? I don't know whats wrong... the system locks up or freezes when I try and run it. Can you find something wrong because I can't. Oh and when you run the program you have to have caps on, I think.
//Filename:frcrnrs.cpp
//Function: A simple game of Four Corners
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#define left arrow = 'A'
#define up arrow = 'Q'
#define down arrow = 'X'
#define right arrow = 'Z'
void main()
{
int crn;
cout << "~Four Corners~" << endl;
cout << endl << "Controls: " << endl;
cout << "S Top Right" << endl;
cout << "A Top Left" << endl;
cout << "X Bottom Right" << endl;
cout << "Z Bottom Left" << endl << endl;
cout << "# *" << endl;
cout << endl << endl << endl << endl << endl << endl << endl << endl;
cout << "# #";
cout << endl << endl;
int lp=1;
while(lp!=0);
{
int rnd;
rand();
rnd=rand()%4;
char ch;
ch=getch();
if(ch == 'S')
{
crn=1;
clrscr();
cout << "# *" << endl;
cout << endl << endl << endl << endl << endl << endl << endl << endl;
cout << "# #";
cout << endl << endl;
}
if(ch == 'A')
{
crn=2;
clrscr();
cout << "* #" << endl;
cout << endl << endl << endl << endl << endl << endl << endl << endl;
cout << "# #";
cout << endl << endl;
}
if(ch == 'Z')
{
crn=3;
clrscr();
cout << "# #" << endl;
cout << endl << endl << endl << endl << endl << endl << endl << endl;
cout << "* #";
cout << endl << endl;
}
if(ch == 'X')
{
crn=4;
clrscr();
cout << "# #" << endl;
cout << endl << endl << endl << endl << endl << endl << endl << endl;
cout << "# *";
cout << endl << endl;
}
int chc;
cout << "Are you sure?" << endl << "1. Yes" << endl << "2. No" << endl;
cin >> chc;
if(chc == 1)
{
if(crn==rnd)
{
clrscr();
cout << " ~You Win~";
}
else if(crn>rnd)
{
cout << " ~You Loose~";
}
else if(crn<rnd)
{
cout << " ~You Loose~";
}
}
else if(chc==2)
{
getch();
}
}
}
-
>int lp=1;
>while(lp!=0); ...
two problems, first problem is that is doesnt seem your code ever changes 'pl' to false, so you keep on looping. Second, you have a semicolon after your while loop
-
Student
Thanx
Thanx, that did the trick.
-
Registered User
Not to mention you're declaring variables inside a loop.
-
When you post code, use code tags.
Popular pages
Recent additions