cout not working properly

This is a discussion on cout not working properly within the C++ Programming forums, part of the General Programming Boards category; Code: /*****************************************************************************\ | This program will compile with Borland 5.5 or higher. | \*****************************************************************************/ #include <iostream> #include <conio> // for ...

  1. #1
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    859

    cout not working properly

    Code:
    /*****************************************************************************\
    |            This program will compile with Borland 5.5 or higher.            |
    \*****************************************************************************/
    
    
    #include <iostream>
    #include <conio> // for gotoxy + getch
    #include <cstdio> // for getchar
    #include <cstdlib>
    #include <new> // for the error handler
    #include <cstring>
    #include <ctime> //for delay + randomize
    #include <windows>
    #include <fstream>
    
    using namespace std;
    
    //#define Tgreen SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN)
    //#define Tint SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY)
    
    #define AR_MAX 9 // array maximum
    #define TOP 17 // the top of the control panel
    #define MENU_TOP 20 // top of the menu
    #define MENU_BTM 23 // bottom of the menu
    
    #define STR 0 // defines the position of certain abilities in the array
    #define AGL 1 // agility
    #define INT 2 // mana point
    #define MP_CRT 3  // current MANA
    #define MP_MAX 4 // max mana
    #define HP_CRT 5  // current HP
    #define HP_MAX 6 // max hp
    #define LVL 7 // level
    #define LM 8  // Lazy meter :)
    #define _a y++ // used in the hero attribute display
    #define name char const hero_name[256] // used when calling to a function (I am lazy ok??? :p )
    
    int* status = new int [AR_MAX];              // attribute storage
    
    int message = MENU_TOP; // where what line to put message
    
    char* msg1; // message 1
    char* msg2;
    char* msg3;
    char* msg4;
    
    //******************************8
    
    void stop_watch(double seconds)
    {
      clock_t endwait;
      endwait = (clock () + seconds * CLK_TCK );
      while (clock() < endwait) {}
    }
    
    //******************************8
    
    void message_box(char* passage)
    
    /* this function put the messages in the message box into the log file
       Also, it will adjust itself when the message box has more than 4
       messages. (ie 4 to 3, 3 to 2, and so on...).
    */
    
    {
    
       ofstream log_file;
    
       log_file.open("message.log", ios::app);
    
       gotoxy(39,message);
       cout << passage;
    
       	message++;
    
       if (message == 21)
       	msg1 = passage;
    
       else if (message == 22)
       	msg2 = passage;
    
       else if (message == 23)
       	msg3 = passage;
    
       else if (message == 24){ // shift up
       	message = 23;
          msg1 = msg2;
          msg2 = msg3;
          msg3 = msg4;
          msg4 = passage;
       }
    
       log_file << passage << endl;
       log_file.close();
    
       return;
    
    }
    
    //******************************8
    
    void mem_error(void)
    
    /* if there is a problem... */
    
    {
    
       cerr << "Fatal Error (Out of Memory)";
       getchar();
       clrscr();
       abort();
    
    }
    
    //******************************8
    
    void exit_prgm(void)
    
    /* called when the program exits */
    
    {
    
       delete []status; // kill kill kill!!!
       printf("Clean Run");
       getchar();
       clrscr();
    
    }
    
    //******************************8
    
    void attribute_change(int const type, int const a)
    
    /* this function will change the integer on a requested attribute */
    
    {
    
       status[type] += a;
    
       return;
    
    }
    
    //******************************8
    
    void reset_attribute(int x)
    
    /* reset the attribute if needs arises (like when starting a new game) */
    
    {
       int set;
    
       set = 10 + (rand()%10); // reset to 10-20
       status[x] = set; // put to array
    
       if (x == MP_MAX) // adjust if current mana is higher than max mana
       	status[MP_CRT] = status[MP_MAX];
    
       else if (x == HP_MAX) // same thing for hp
       	status[HP_CRT] = status[HP_MAX];
    
       else if (x == LVL) // level!!
       	status[LVL] = 1;
    
       else if (x == LM) // the lazy meter (1-10)
       	status[LM] = 1 + rand()%10;
       return;
    
    }
    
    //******************************8
    
    void display_attribute(int const x, int y, name)
    
    /* display the attribute of hero in the left area of the control panel */
    
    {
       //Tgreen;
    
       gotoxy(x,y);
       cout << hero_name << endl;
       gotoxy(20,y);
       cout << status[LVL] << endl;
       //Tint;
       _a;
       gotoxy(x,y);
       cout << "Strength: " << status[STR] << endl;
    
       _a;
       gotoxy(x,y);
       cout << "Agility : " << status[AGL] << endl;
    
       _a;
       gotoxy(x,y);
       cout << "Mana Erg: " << status[INT] << endl;
    
       _a;
       gotoxy(x,y);
       cout << "Lazy Mtr: " << status[LM] << endl;
    
       _a;
       gotoxy(x,y);
       cout << "Magic Pt: " << status[MP_CRT] << "/" << status[MP_MAX] << endl;
    
       _a;
       gotoxy(x,y);
       cout << "Hit Pt  : " << status[HP_CRT] << "/" << status[HP_MAX] << endl;
    
       return;
    
    }
    
    //******************************8
    
    void fight()
    
    /* pick a fight UNFINISHED */
    
    {
    
       attribute_change(MP_MAX, rand()%5);
       attribute_change(HP_MAX, rand()%5);
       attribute_change(LVL, 1);
    
       message_box("Max Magic Pt increased!");
       message_box("Max Health increased!");
       message_box("Level increased!");
    
    	return;
    
    }
    
    //******************************8
    
    void heal()
    
    /* heals:
       When max hp is lower than current hp, it will adjust itself, same for mana
       will only restore one thing at a time, from 0 to 30                         */
    
    {
       int HP = rand()%30; // random heals amounts
       int MP = rand()%30;
    
       int MPorHP = rand()%2; // determine whether to heal mana or hp
    
       if ( (HP + status[HP_CRT]) > status[HP_MAX]) // check if current hp is higher than max hp
       	HP = status[HP_MAX] - status[HP_CRT];
    
       if ( (MP + status[MP_CRT]) > status[MP_MAX]) // same thing for mana
       	MP = status[MP_MAX] - status[MP_CRT];
    
       if (MPorHP == 0){ // if picked 0
       	attribute_change(HP_CRT, HP);
          message_box("Hit Points Restored!!");
       }
    
       else{ // else
    		attribute_change(MP_CRT, MP);
          message_box("Magic Points Restored!!");
       }
    
    	return;
    
    }
    
    //******************************8
    
    void credits()
    
    /* display the credits in the message box           */
    
    {
    
       message_box("-----------------------");
    	message_box("Credits");
       message_box(" ");
    
       stop_watch(2);
    
       message_box("Programmed by: someone");
       message_box("Graphics by  : someone");
       message_box("-----------------------");
    
    	return;
    
    }
    
    //******************************8
    
    void options(int Y)
    
    /* this function will check the position of the scroll bar
       and execute the correct command                         */
    
    {
    
    		if (Y == 20) // the fight position
    
    			fight();
    
    		else if (Y == 21) // the heal position
    
    			heal();
    
    		else if (Y == 22) // the about position
    
    			credits();
    
    		else // the exit position
    			exit(0);
    	return;
    
    }
    
    //******************************8
    
    void menu(int key, int &Y)
    
    /* this function will detect the movement of the scroll bar
       (up or down). This will also do the appropiate action
       when the enter key is hit                                 */
    
    {
    
    		if (key == 72 && Y > MENU_TOP)
    
    			--Y;
    
    		else if (key == 80 && Y < MENU_BTM)
    
    			++Y;
    
    		else if (key == 13)
    
    			options(Y);
    
    	return;
    
    }
    
    //******************************8
    
    void display_msg()
    
    /* will display 4 messages at the message box */
    
    {
    
       gotoxy(39,MENU_TOP);
    	cout << msg1;
    
       gotoxy(39,MENU_TOP + 1);
    	cout << msg2;
    
       gotoxy(39,MENU_TOP + 2);
    	cout << msg3;
    
       gotoxy(39,MENU_TOP + 3);
    	cout << msg4;
    
       return;
    
    }
    
    //******************************8
    
    void display_HUD(name, int const Y)
    
    /* This function will display the control panel */
    
    {
    
    	char* HUD = "\
    浜様様様様様様僕様様様僕曜曜様様様僕僕様様様様様様様様様様様様様様様様様様様様融\
                 LVL:   +-麺陵MENU洋郵 MESSAGES                                 \
                 藩様様様                                                  \
                            Fight!                                           \
                            Heal                                             \
                            About                                            \
                            Exit                                             \
                                                                           \
    藩様様様様様様様様様様瞥擁擁様様様瞥瞥様様様様様様様様様様様様様様様様様様様様"/**/;
    
       gotoxy(1,TOP);
       cout << HUD;
    
       if (status[LM] >= 8){ // if lazy meter is equal to or higher than 8
    	  gotoxy(1,TOP-1);
          cout << "DANGER, MIGHT FALL ASLEEP DURING ACTION!";
       }
    
       display_attribute(3,TOP+1,hero_name); // display the stats
       display_msg(); // display the messages
       gotoxy (27, Y); // display the left scroll bar
       cout << "";
    
       gotoxy (36, Y); // display the right scroll bar
       cout << "";
    
       return;
    
    }
    
    //******************************8
    
    int main()
    
    {
    
       srand(time(NULL));
    
       ofstream log_file; // start a log file
    
       log_file.open("message.log", ios::app); // open the log file
    
       time_t hold_time; // initialize the time
    
       hold_time = time(NULL);
    
       log_file << endl << "------Start logging at " << ctime(&hold_time) << endl; // put the time at the log file to separate previous entries
    
       log_file.close(); // close it
    
       /*=======INITIALIZATION=======*/
    
    	atexit(exit_prgm);              // set to point to this function when exiting
        set_new_handler(mem_error);     // set to point to this function when a memory error occurs
    
    	for (int x = 0; x < AR_MAX; ++x) // set all the attribute to random
       	reset_attribute(x);
    
       /*====FURTHER DECLARATIONS====*/
    
    	char hero_name[256]; // name of hero
    	int Y = MENU_TOP;
    	int key;
    
       /*============================*/
    
       // THE INTRODUCTION SCREEN GOES HERE
    
       cout << "Temp RPG" << endl;
       cout << "Name of our Hero: ";    // ask for name
       cin.getline(hero_name, 256, '\n');
       cout << "Hello, " << hero_name << endl;
    
       clrscr();
    
       //display_attribute(10,10, hero_name);
    
       do{
    
    		if(kbhit()){
    
    			key = getch();
    			menu(key, Y); // check for the keys
    			display_HUD(hero_name, Y); // display the panel
    
    		}
    
       }while(key != 27); // until the escape key is hit
    
       return 0;
    
    }
    
    //******************************8
    after the cin thing, the "cout" no longer works... but everything else works. Why?
    Last edited by Yoshi; 12-11-2002 at 10:26 PM.
    Yoshi

  2. #2
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    859
    sorry for the tabs. Apparently Borland 5 and textpad 4 don't agree on tabs
    Yoshi

  3. #3
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Define "not working properly"
    What exactly is it doing?

  4. #4
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    859
    outputs nothing
    Attached Images Attached Images  
    Yoshi

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Urge to answer question fading. fading. gone.

  6. #6
    Spanky devour89's Avatar
    Join Date
    Nov 2002
    Posts
    148
    Wraith_Master

    I know this has nothing to do with your question but how did you make that nice looking menu. Can you tell me how the basics go so I can try some stuff to.

    Thanks in Advanced

    -Devouring One-

  7. #7
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    859
    i drew that in

    use character map and practically "draw" it in...

    EDIT: BTW, this is Win 2000 on the school's computer. and strangely enough... it works.

    EDIT: BTW, i cheated on this game so it is level 6 without any fighting.
    Attached Images Attached Images  
    Last edited by Yoshi; 12-12-2002 at 10:07 AM.
    Yoshi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. why isn't my loop working properly?
    By orion- in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2005, 06:23 PM
  2. Picking: not working properly
    By psychopath in forum Game Programming
    Replies: 1
    Last Post: 09-06-2005, 06:18 PM
  3. Homework due tonight! help please!!
    By Andy717 in forum C++ Programming
    Replies: 41
    Last Post: 04-07-2005, 02:18 PM
  4. I'm REALLY confused. Why isn't cout or cin working here?
    By niudago in forum C++ Programming
    Replies: 8
    Last Post: 02-15-2003, 05:53 PM
  5. Redirecting cout stream
    By Arrow Mk84 in forum C++ Programming
    Replies: 1
    Last Post: 10-08-2002, 05:17 PM

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