Created
September 17, 2013 23:56
-
-
Save kdmkdmkdm/6602476 to your computer and use it in GitHub Desktop.
if-else help
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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