Thread: newb help

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    10

    newb help

    can you help me out with this code i was workin on, it says ther is an error and i cant seem to find it
    thanks

    Code:
    // Destiny1.cpp : Defines the entry point for the console application.
    #include <conio.h>
    #include <stdlib.h>
    #include <iostream.h>
    using namespace std;
    
    
    
    int two=2;
    int zero=0;
    int *hp;
    int *xp;
    int *ac;
    int *dmg;
    char *nme;
    char *cls;
    char *rce;
    
    
    int chrdefine()
    {
    	//Name
       char name[100];
    	cout << "Name: ";
    	cin>>name;
    	nme=name;
    
    	//Class
    	system("cls");
    	cout << "Class: " <</n;
    	cout << "1. Mage" << /n;
    	cout << "2. Fighter" << /n;
    	cout << "3. Monk" << /n;
    	cout << "Other Key To Quit" << /n;
    	int ch1=getch();
    	switch(ch1)
    	{
    		case 1:
    		cls="Mage";
    		break;
    
    		case 2:
    		cls="Fighter";
    		break;
    
    		case 3:
    		cls="paledan";
    		break;
    
    		default:
    		return 0;
    		break;
    	}
    
    
    	//Race
    	system("cls");
    	cout << "Race: " << /n;
    	cout << "1. Human" << /n;
    	cout << "2. Elf" << /n;
    	cout << "3. Halfling" << /n;
    	cout << "4. Half-Elf" << /n;
    	cout << "5. Half-Orc" << /n;
        cout << "6. Orc" << /n;   
        cout << "7. faery" << /n;
    	cout << "Other Key To Quit" << /n;
    	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;
                   
                    case 6:
    		rce="orc";
    		break;
     
                    case 7:
    		rce="faery";
    		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 << /n;
    	cout << "Name: " << *nme << /n;
    	cout << "Race: " << *rce << /n;
    	cout << "Class: " << *cls << /n;
    	cout << "EXP: " << *xp << /n;
    	cout << "AC: +" << *ac << /n;
    	cout << "Damage: " << *dmg << /n;
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    10
    and im using ms VC6

  3. #3
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    23 errors.

    1) /n should be "\n"

    2) i removed namespace std because i beleive it needed another included header file, i don't use NS so i dunno.

    I fixed it for you, heres the working code, study and learn my newbie buddy!

    Code:
    // Fixed by Steven Billington
    // its "\n" not /n
    // removed namespace line
    
    // Destiny1.cpp : Defines the entry point for the console application.
    #include <conio.h>
    #include <stdlib.h>
    #include <iostream.h>
    
    
    
    
    int two=2;
    int zero=0;
    int *hp;
    int *xp;
    int *ac;
    int *dmg;
    char *nme;
    char *cls;
    char *rce;
    
    
    int chrdefine()
    {
    	//Name
       char name[100];
    	cout << "Name: ";
    	cin>>name;
    	nme=name;
    
    	//Class
    	system("cls");
    	cout << "Class: " <<"\n";
    	cout << "1. Mage" << "\n";
    	cout << "2. Fighter" << "\n";
    	cout << "3. Monk" << "\n";
    	cout << "Other Key To Quit" << "\n";
    	int ch1=getch();
    	switch(ch1)
    	{
    		case 1:
    		cls="Mage";
    		break;
    
    		case 2:
    		cls="Fighter";
    		break;
    
    		case 3:
    		cls="paledan";
    		break;
    
    		default:
    		return 0;
    		break;
    	}
    
    
    	//Race
    	system("cls");
    	cout << "Race: " << "\n";
    	cout << "1. Human" << "\n";
    	cout << "2. Elf" << "\n";
    	cout << "3. Halfling" << "\n";
    	cout << "4. Half-Elf" << "\n";
    	cout << "5. Half-Orc" << "\n";
        cout << "6. Orc" << "\n";   
        cout << "7. faery" << "\n";
    	cout << "Other Key To Quit" << "\n";
    	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;
                   
                    case 6:
    		rce="orc";
    		break;
     
                    case 7:
    		rce="faery";
    		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 << "\n";
    	cout << "Name: " << *nme << "\n";
    	cout << "Race: " << *rce << "\n";
    	cout << "Class: " << *cls << "\n";
    	cout << "EXP: " << *xp << "\n";
    	cout << "AC: +" << *ac << "\n";
    	cout << "Damage: " << *dmg << "\n";
    	return 0;
    
    }
    Last edited by RoD; 10-05-2002 at 02:00 PM.

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    10
    thanks my friend

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    10
    hmmmmm

    --------------------Configuration: Destiny1 - Win32 Debug--------------------
    Compiling...
    Destiny1.cpp
    c:\program files\microsoft visual studio\myprojects\destiny1\destiny1.cpp(132) : fatal error C1004: unexpected end of file found
    Error executing cl.exe.

    Destiny1.obj - 1 error(s), 0 warning(s)

  6. #6
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    make sure when u copied it from my post u got the last } , because it compiles 100% fine for me.

  7. #7
    Registered User Kirdra's Avatar
    Join Date
    Aug 2002
    Posts
    105
    You should use standard header files i.e. <iostream.h> should be changed to <iostream>.

  8. #8
    Registered User
    Join Date
    Sep 2002
    Posts
    10
    when i do that there are multiple more errors
    i got the code to complile and build but when i run it after i input the name nuthing happens, can someone help me out?
    Code:
    // Fixed by Steven Billington
    // its "\n" not /n
    // removed namespace line
    
    // Destiny1.cpp : Defines the entry point for the console application.
    #include <conio.h>
    #include <stdlib.h>
    #include <iostream.h>
    
    
    
    
    int two=2;
    int zero=0;
    int *hp;
    int *xp;
    int *ac;
    int *dmg;
    char *nme;
    char *cls;
    char *rce;
    
    
    int chrdefine()
    {
    	//Name
       char name[100];
    	cout << "Name: ";
    	cin>>name;
    	nme=name;
    
    	//Class
    	system("cls");
    	cout << "Class: " <<"\n";
    	cout << "1. Mage" << "\n";
    	cout << "2. Fighter" << "\n";
    	cout << "3. Monk" << "\n";
    	cout << "Other Key To Quit" << "\n";
    	int ch1=getch();
    	switch(ch1)
    	{
    		case 1:
    		cls="Mage";
    		break;
    
    		case 2:
    		cls="Fighter";
    		break;
    
    		case 3:
    		cls="paledan";
    		break;
    
    		default:
    		return 0;
    		break;
    	}
    
    
    	//Race
    	system("cls");
    	cout << "Race: " << "\n";
    	cout << "1. Human" << "\n";
    	cout << "2. Elf" << "\n";
    	cout << "3. Halfling" << "\n";
    	cout << "4. Half-Elf" << "\n";
    	cout << "5. Half-Orc" << "\n";
        cout << "6. Orc" << "\n";   
        cout << "7. faery" << "\n";
    	cout << "Other Key To Quit" << "\n";
    	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;
                   
                    case 6:
    		rce="orc";
    		break;
     
                    case 7:
    		rce="faery";
    		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 << "\n";
    	cout << "Name: " << *nme << "\n";
    	cout << "Race: " << *rce << "\n";
    	cout << "Class: " << *cls << "\n";
    	cout << "EXP: " << *xp << "\n";
    	cout << "AC: +" << *ac << "\n";
    	cout << "Damage: " << *dmg << "\n";
    	return 0;
    }

  9. #9
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    I told you, its in your int main. Something is wrong with your pointers:

    *hp, *xp, and so on. If you remove them your program runs, but as i told you i have no experience with pointers and that you needed to post being specific to that are of code.

  10. #10
    Registered User
    Join Date
    Sep 2002
    Posts
    10
    i took out the pointers in int main, it runs fine but i still have the same problem

  11. #11
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    Just one thing, getch() returns a character, but an ASCII character. So your switch () will check for ascii code '1', which is not the same as numeric code 1. replace case 1: with case '1':, and so on...
    .sect signature

  12. #12
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    well, there are other errors. but here's one that you can't let slip:

    //Hp
    int random=rand()%10;
    random=random+11;
    hp=&random;
    return 0;

    random is declared as an integer in the scope of the function chrdefine(). however, when the function exits (return 0) random no longer really exists - and the pointer hp points to a bit of memory that any other function may change the value of. You shouldn't use pointers like that for all of your numeric values.
    .sect signature

  13. #13
    Registered User
    Join Date
    Sep 2002
    Posts
    10
    i tried doing some of the stuff you said, buit it wont work

    Code:
    // Destiny1.cpp : Defines the entry point for the console application.
    #include <conio.h>
    #include <stdlib.h>
    #include <iostream.h>
    
    
    
    
    int two=2;
    int zero=0;
    int *hp;
    int *xp;
    int *ac;
    int *dmg;
    char *nme;
    char *cls;
    char *rce;
    
    
    int chrdefine()
    {
    	//Name
       char name[100];
    	cout << "Name: ";
    	cin>>name;
    	nme=name;
    
    	//Class
    	system("cls");
    	cout << "Class: " <<"\n";
    	cout << "1. Mage" << "\n";
    	cout << "2. Fighter" << "\n";
    	cout << "3. Monk" << "\n";
    	cout << "Other Key To Quit" << "\n";
    	int ch1=getch();
    	switch(ch1)
    	{
    		case '1':
    		cls="Mage";
    		break;
    
    		case '2':
    		cls="Fighter";
    		break;
    
    		case '3':
    		cls="paledan";
    		break;
    
    		default:
    		return 0;
    		break;
    	}
    
    
    	//Race
    	system("cls");
    	cout << "Race: " << "\n";
    	cout << "1. Human" << "\n";
    	cout << "2. Elf" << "\n";
    	cout << "3. Halfling" << "\n";
    	cout << "4. Half-Elf" << "\n";
    	cout << "5. Half-Orc" << "\n";
        cout << "6. Orc" << "\n";   
        cout << "7. faery" << "\n";
    	cout << "Other Key To Quit" << "\n";
    	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;
                   
                    case '6':
    		rce="orc";
    		break;
     					 
                    case '7':
    		rce="faery";
    		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 << "\n";
    	cout << "Name: " << nme << "\n";
    	cout << "Race: " << rce << "\n";
    	cout << "Class: " << cls << "\n";
    	cout << "EXP: " << xp << "\n";
    	cout << "AC: +" << ac << "\n";
    	cout << "Damage: " << dmg << "\n";
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newb Question Character Counting
    By Wilder in forum C Programming
    Replies: 13
    Last Post: 06-22-2008, 11:37 PM
  2. Dogpile the newb!
    By lindy in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 05-23-2008, 08:17 AM
  3. Total newb directx invisable geometry question
    By -pete- in forum Game Programming
    Replies: 5
    Last Post: 08-13-2006, 01:45 PM
  4. Newb C++ Programmer
    By Philandrew in forum C++ Programming
    Replies: 8
    Last Post: 10-19-2004, 08:44 PM
  5. if your not newb you can help me
    By Klinerr1 in forum C++ Programming
    Replies: 6
    Last Post: 05-05-2002, 12:09 AM