I''ve never encountered something like this before; it has me baffled
![](tongue.gif)
I''m trying to write a small strategy game (loosely based on Adavance Wars for GBA) using just text graphics to test out some of my ideas before I try and design a DirectX version. As luck would have it, however, I encountered one of the strangest errors I''ve ever seen by just making the menu. Here is the complete code (using MSVC++ 6.0, btw):
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
//GLOBALS
struct Unit
{
int UnitId; //numerical world ID of unit
int TypeID; //type of unit ID
char name[20]; //name of unit
int hp; //hp (max: 10)
int ammo; //amount of ammo left
int range; //amount of squares a unit can fire
int move; //amount of squares a unit can move
int los; //amount of squares a unit can see
int XCoord; //x coordinate
int YCoord; //y coordinate
bool selected; //determines if an object is selected
};
//FUNCTION PROTOTYPES
int SelectCommander();
int GetInput();
int main()
{
SelectCommander();
return(1);
}
int SelectCommander()
{
cout<<"Player 1 -- Select a Commander: \n\n";
cout<<"Blah1: BONUSES: - Infantry class units deploy cost -20%\n";
cout<<" - Infantry class units +15% damage\n\n";
cout<<"Blah2: BONUSES: - APC move +2 squares\n";
cout<<" - All units move +1 square\n";
cout<<" - All units 10% cheaper\n\n";
cout<<"Blah3: BONUSES: - Tank class units +30% strength\n";
cout<<" - Missile class units cost 15% more\n";
cout<<" - Missile class units -10% damage\n\n";
cout<<"Blah4 BONUSES: - Bio soldier damage +2\n";
cout<<" - Cannot build Tank class units\n";
cout<<" - Bio soldier cost +20%\n\n";
cout<<"Blah5 BONUSES: - All units +2 LOS\n";
cout<<" - Radar range +2 squares\n";
cout<<" - Missile unit range +1 square\n\n";
switch(GetInput())
{
case 106: //j (Blah1)
{
cout<<"-- Blah1--";
} break;
default: break;
}//end switch
return(1);
}
int GetInput()
{
int choice = 0;
while(!(kbhit()))
{
if (_kbhit())
{
choice = getch();
}//endif
}//end while
return(choice);
}//end GetInput()
Okay, so if you run this program, it should logically print out the complete list of descriptions and then wait for input, right? Not so. Here is the output:
* CUT TO SAVE SPACE
Blah4 BONUSES: - Bio soldier damage +2
j
- Cannot build Tank class units
- Bio soldier cost +20%
Blah5 BONUSES: - All units +2 LOS
- Radar range +2 squares
- Missile unit range +1 square
j
Press any key to continue
Shouldn''t all the cout<< statements logically execute before the input loop? Right now, it prints up to the "BONUSES: - Bio soldier damage +2", then stops and waits for input, and then prints the rest of the list. I can''t seem to figure out _why_ it would just stop cout<<-ing in the middle of the descriptions and continue after the input. It just doesn''t make sense (to me)
Thanks for any help