Thread: Help

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Exclamation 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();
    }
    }
    }

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    >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

  3. #3
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Thanx

    Thanx, that did the trick.

  4. #4
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    Not to mention you're declaring variables inside a loop.

  5. #5
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    When you post code, use code tags.

Popular pages Recent additions subscribe to a feed