if statement

This is a discussion on if statement within the Game Programming forums, part of the General Programming Boards category; ok would i put an if statement in the code if i wanted some one to pick yes or no. ...

  1. #1
    Registered User Joe100's Avatar
    Join Date
    Jul 2003
    Posts
    63

    if statement

    ok would i put an if statement in the code if i wanted some one to pick yes or no.
    where i think the if statement should go is in bold letters. If im inccorect can u please correct me in the matter or just tell me that im completly wrong if I am.
    Code:
    //Remembers:
    #include <iostream.h>
    #include <conio.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>
    //#include <Strings.h>
    
    #define WEP_Knife 1
    #define WEP_Pulse Rifle 2
    #define WEP_Shotgun 3
    #define WEP_Smartgun 4
    #define WEP_Sniper Rifle 5
    #define WEP_Rocket Launcher 6
    #define WEP_Mini Gun 7
    #define WEP_Dual Pistols 8
    #define WEP_Pistols 9
    class Monster
    {
    public:
    	Monster(int,int);
       Monster(){};
       ~Monster(){};
    	int hp;
    	int attack;
    };
    Monster::Monster(int HP,int ATTACK)
    {
    	hp=HP;
    	attack=ATTACK;
    }
    class Character
    {
    public:
       Character(int,int,int);
    	Character(){};
       ~Character(){};
       int hp;
    	int attack;
       int inventory;
       int exp;
    
    };
    Character::Character(int HP,int ATTACK,int INV)
    {
    	hp=HP;
    	attack=ATTACK;
       inventory=INV;
    
    }
    void TextPrint(char Sentence[],int sleep);
    void DrawMenu(); // function prototype
    int RandDice(int,int);
    void Credits();
    int RandMonster(int,int,int,int,int,int,int,int,int);
    int main()
    {
    	srand(GetTickCount());
    	char Name[100];
    	int MenuChoice;
    	int ClassChoice;
    
       //Character player;
       //Character.hp=100;
    	//Character.attack=RandDice(30,100);
       //Character.inventory=(1,2,3,4);
    
    
    
    	Monster Predator(10,RandDice(30,50));
       Monster HeavyPredator(10,RandDice(30,50));
       Monster AssualtPredator(10,RandDice(30,50));
       Monster LightPredator(10,RandDice(30,50));
       Monster LuciferPredator(10,RandDice(30,50));
       Monster Drone(20,RandDice(20,30));
       Monster Predalien(20,RandDice(20,30));
       Monster Runner(20,RandDice(20,30));
       Monster Pretorion(20,RandDice(20,30));
    	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),8);
    	while(1)
       {
       	DrawMenu();
       	cin >> MenuChoice;
    		switch(MenuChoice)
    		{
    		case 1:
    			cout << "you chose start game! \n";
    			break;
    		case 2:
    			cout << "you chose load game! \n";
    			break;
    		case 3:
    			Credits();
    			break;
    		default:
    			cout << "That wasn't one of the choices \n";
    			continue;
    		}
       	break;
       }
       clrscr();
    	cout << "Please enter your character's name \n";
    	cin >> Name;
       clrscr();
    	cout << "Welcome to G-Unit Sector "<<Name<<"\n";
    	cout << "please choose a character class \n";
    	cout << "\t\t *********Character classes******** \n";
    	cout << "\t\t *                                * \n";
    	cout << "\t\t * 1.Marine                       * \n";
    	cout << "\t\t * 2.Corporate                    * \n";
    	cout << "\t\t *                                * \n";
    	cout << "\t\t *                                * \n";
    	cout << "\t\t ********************************** \n";
    	cin >> ClassChoice;
    	switch(ClassChoice)
    	{
    		case 1:
    			cout << "you chose to be a Marine  \n";
    			break;
    		case 2:
    			cout << "you chose to be a corporate \n";
    			break;
    	}
      	clrscr();
    	TextPrint("insert text here",40);
    	getch();
       clrscr();
       cout << "insert text here"
    <<Name<<"insert text here\n";
    	cout << "insert text here "<<Name<<"insert text here\n";
    	getch();
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED); cout <<"insert text here\n";
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),8);
    	TextPrint("insert text here",40);
    	getch();
    	clrscr();
       cout << "insert text here\n";
       cin >> Name;
       cout << "insert text here\n";
       cout << "insert text here\n";
       cout << "y/n\n"
       cin >> name;
     // would the if statment go here
    	getch();
       return 0;
    }
    void DrawMenu() // function definition
    {
    	cout << "\t\t ************Start Menu************* \n";
    	cout << "\t\t *                                 * \n";
    	cout << "\t\t * 1.start game                    * \n";
    	cout << "\t\t * 2.load game                     * \n";
    	cout << "\t\t * 3.credits                       * \n";
    	cout << "\t\t *                                 * \n";
    	cout << "\t\t *********************************** \n";
    }
    int RandDice(int low, int high)
    {
     	return (rand() % (low - high + 1) + low);
    }
    void Credits()
    {
    	clrscr();
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE); TextPrint("This game was brought to by Joe M. \n\
    Programmed by: Inferno \n\
    Inspired By: Stan100 and [GU]Lord Soth{CM} \n\
    sepcial thanks: Stan100 \n\
    Copyrighted @ 2003 by Inferno corp.",40);
    	getch();
    	exit(0);
    }
    void TextPrint(char Sentence[],int sleep)
    {
    	for(int a=0;a<strlen(Sentence); a++)
    	{
       cout << Sentence[a];
       Sleep(sleep);
       }
    }
    "Be Quick Or Be Dead"

    [img]
    http://www.danasoft.com/sig/GU.jpg
    [/img]

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code:
    cin >> Answer;
    if(strcmp(Answer, "Yes") == 0)
    {
       //Do yes
    }
    else if(strcmp(Answer, "No") == 0)
    {
       //Do no
    }
    else
    {
       //Do others
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 06:19 AM
  2. Meaning of this statement?
    By @nthony in forum C Programming
    Replies: 7
    Last Post: 07-16-2006, 03:57 AM
  3. if/break statement
    By Apropos in forum C++ Programming
    Replies: 7
    Last Post: 02-22-2005, 02:33 PM
  4. string & if statement
    By Curacao in forum C++ Programming
    Replies: 4
    Last Post: 05-02-2003, 10:56 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM

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