Skip to content

Instantly share code, notes, and snippets.

@kdmkdmkdm
Created September 17, 2013 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdmkdmkdm/6602476 to your computer and use it in GitHub Desktop.
Save kdmkdmkdm/6602476 to your computer and use it in GitHub Desktop.
if-else help
// 2.6elseif.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
// Output some text asking the user to make a selection.
cout << "Welcome to Text-RPG 1.0" << endl;
cout << "Please select a character class number..." << endl;
cout << "1) Fighter 2) Wizard 3) Cleric 4) Theif : ";
// Prompt user to make a selection
int characterNum = 1;
cin >> characterNum;
// Initialize character variables to default value.
int numHitpoints = 0;
int numMagicPoints = 0;
string weaponName = "";
string className = "";
if ( characterNum == 1 ) // Fighter selected?
{
int numHitpoints = 10;
int numMagicPoints = 4;
string weaponName = "Sword";
string className = "Fighter";
}
else if ( characterNum == 2 ) // Wizard selected?
{
int numHitpoints = 2;
int numMagicPoints = 10;
string weaponName = "Magic Staff";
string className = "Wizard";
}
else if ( characterNum == 3 ) // Cleric selected?
{
int numHitpoints = 7;
int numMagicPoints = 7;
string weaponName = "Magic Staff";
string className = "Cleric";
}
else // Not 1, 2, or 3, so select theif.
{
int numHitpoints = 8;
int numMagicPoints = 6;
string weaponName = "Short Sword";
string className = "Theif";
}
cout << endl;
cout << "Character properties:" << endl;
cout << "Class name = " << className << endl;
cout << "Hitpoints = " << numHitpoints << endl;
cout << "Magicpoints = " << numMagicPoints << endl;
cout << "Weapon = " << weaponName << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment