Please help

This is a discussion on Please help within the C++ Programming forums, part of the General Programming Boards category; Hello I'm working on the begining of a text based rpg and I'm having trouble already. There seems to be ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    2

    Please help

    Hello I'm working on the begining of a text based rpg and I'm having trouble already. There seems to be a problem here
    Code:
    void mage()
    {
    	health = 100;
    	mana = 50;
    
    	cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
    	title();
    	cout << "\n\n\n\n\n\n\n\n\n\n\n";
    	cout << "Ah, a man of wisdom and magic." << '\n';
    	cout << "\n";
    	cout << "Is this correct?" << '\n';
    	cout << "\n";
    	cout << "Press y for yes and n for no." << '\n';
    
    	switch(yes_no)
    	{
    		case 'y':
    			mage2();
    			con = 1;
    			break;
    		case 'n':
    			race_f();
    			con = 1;
    			break;
    		default:
    			cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
    			cout << "Not too bright, huh? y or n" << '\n';
    			cout << "\n\n";
    			con = 0;
    			break;
    	}
    	
    	while (con == 0);
    
    }
    it only goes to "press y fo" then it doesnt say any more and you cant type anymore. Can someone help me please?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,631
    It looks like you actually have to read in something. Incidentally, have you considered an object oriented approach instead? OOP seems good for things like this.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    2
    I think i need to flush the screen but i'm not sure how to do that

  4. #4
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    You never read a line from the console with "cin". Have a look at this tutorial to learn how to read a string from the console.

    Also, your while construction is flawed, he will go into an infinite loop.
    You need to write:
    Code:
    do
    {
    switch() ...
    } while (condition);

Popular pages Recent additions subscribe to a feed

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