My game wont clear screen

This is a discussion on My game wont clear screen within the C++ Programming forums, part of the General Programming Boards category; Im working on an rpg project heres the files : main.cpp Code: #include <cstdlib> #include <iostream> #include <conio> #include "new_game.h" ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    2

    My game wont clear screen

    Im working on an rpg project heres the files :

    main.cpp
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <conio>
    #include "new_game.h"
    #include "load.h"
    #include "help.h"
    using namespace std;
    
    int main(){
        int answer;
        main_menu:
        cout << "RPG Game\n\n\n";
        cout << "1) New Game\n";
        cout << "2) Load Game\n";
        cout << "3) Help\n";
        cout << "4) Exit\n\n";
        cout << "Selection(1 to 5):";
        cin >> answer;
        if (answer == 1){
                   clrscr();
                         new_game();
        }else if (answer == 2){
              clrscr();
                               int load();
        }else if (answer == 3){
              clrscr();
                               help ();
                               goto main_menu;
        }else if (answer == 4) {
                                exit(1);
        }else {
        cout << "\nYou entered an incorrect key.\n";
        system ("PAUSE");
        clrscr();
        goto main_menu;
        }
        system("PAUSE");
    }
    new_game:
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <conio>
    using namespace std;
    
    int health = 100;
    int magic = 60;
    int armour = 5;
    int attack = 3;
    int gold = 120;
    
    int new_game (){
        clrscr();
        cout << "Health:" << health << "Mana:" << magic << "Armour:" << armour << "Attack:" << attack << "\n";
        system("PAUSE");
    }
    help:
    Code:
    #include <iostream>
    #include <cstdlib>
    #include <conio>
    using namespace std;
    int help () {
        clrscr();
            cout << "This is the help file\n";
        system ("PAUSE");
        clrscr();
    }
    No load game, i use int loadgame and i know its there but the program doesnt touch it.

    So heres my problem. With my help and with my newgame functions it will not let me use clrscrn(); so i cant clear the screen. It also doesnt pick up any spaces i put in the armour/health/gold section.

    I have no idea why its doing this as it will clear screen in some parts of the code like after the pause in help file when you hit enter. Thanks in advance

  2. #2
    Registered User
    Join Date
    May 2005
    Location
    Texas
    Posts
    103
    How about instead of using
    Code:
    clrscr();
    to clear the screen, you use
    Code:
    system("cls");
    ?

    else if (answer == 2){
    clrscr();
    int load();
    was int load() declared on your load.h header? Here your just declaring another function called load() on a local scope, which is a function that is not global in contrary to how the functions declared in your headers are, and can only be accessed within the else if block, because it was declared on that scope. Hope that made sense.

    If load() is a function in your header, then try this:
    Code:
    load();
    remove the int, your no longer declaring a function, rather you're calling one.
    Last edited by toonlover; 08-15-2008 at 04:21 AM.
    Be easy on me...only 14

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Why are you using
    Code:
        goto main_menu;
    when it would be much simpler/shorter to add "while" or "do while" to the code to make it loop like you wish?

    Code:
    #include <conio>
    What compiler are you using? Most compilers expect the .h to be there when there is one in the real filename. And I don't think "conio" without a .h exists.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Clear Screen Again!!!
    By trang in forum C Programming
    Replies: 3
    Last Post: 12-13-2003, 08:36 AM
  2. How To Make: Screen Killer (Game)
    By BillBoeBaggins in forum C++ Programming
    Replies: 3
    Last Post: 11-20-2003, 06:06 PM
  3. Yet another clear screen thread :D
    By kermit in forum Linux Programming
    Replies: 2
    Last Post: 11-20-2003, 05:14 AM
  4. How to clear the screen?
    By Zopyrus in forum C++ Programming
    Replies: 8
    Last Post: 11-07-2003, 10:20 PM
  5. Screen section to clear
    By devour89 in forum C++ Programming
    Replies: 1
    Last Post: 12-13-2002, 07:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21