Anyone see what's wrong with this code? I really don't... I assume it's with the pointers, though. Because this is only the second or third time i've used them.
Code:#include <stdlib.h> #include <iostream.h> #include <conio.h> //Define Bool typedef int bool; #define true 1; #define false 0; //Stat Pointers int two=2; int zero=0; int *hp; int *xp; int *ac; int *dmg; char *nme; char *cls; char *rce; //Character Definition int chrdefine() { //Name char name[100]; cout << "Name: "; cin >> nme; nme=name; //Class clrscr(); cout << "Class: " << endl; cout << "1. Mage" << endl; cout << "2. Fighter" << endl; cout << "3. Monk" << endl; cout << "Other Key To Quit" << endl; char ch1=getch(); switch(ch1) { case 1: cls="Mage"; break; case 2: cls="Fighter"; break; case 3: cls="Monk"; break; default: return 0; break; } //Race clrscr(); cout << "Race: " << endl; cout << "1. Human" << endl; cout << "2. Elf" << endl; cout << "3. Halfling" << endl; cout << "4. Half-Elf" << endl; cout << "5. Half-Orc" << endl; cout << "Other Key To Quit" << endl; char ch2=getch(); switch(ch2) { case 1: rce="Human"; break; case 2: rce="Elf"; break; case 3: rce="Halfling"; ac=&two; break; case 4: rce="Half-Elf"; break; case 5: rce="Half-Orc"; break; default: return 0; break; } //Xp xp=&zero; //Hp int random=rand()%10; random=random+11; hp=&random; return 0; } int main() { chrdefine(); cout << "HP: " << *hp << endl; cout << "Name: " << *nme << endl; cout << "Race: " << *rce << endl; cout << "Class: " << *cls << endl; cout << "EXP: " << *xp << endl; cout << "AC: +" << *ac << endl; cout << "Damage: " << *dmg << endl; return 0; }
It runs the beginning of the character function fine, the inputing of the name. It never makes it to where you input your race. Then when it goes to output the data it shows... strange symbols.