simple code bugs for a Console aplication
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: simple code bugs for a Console aplication

Threaded View

  1. #1
    Join Date
    Jul 2011
    Posts
    4

    simple code bugs for a Console aplication

    I am getting a strange bug in my code. I only started coding verry recently and was wondering if someone could explain my problem in very basic terms. this is my code:

    Code:
    #include<iostream>
    #include<string>
    #include<ctime>
    #include<cstdlib>
    
    using namespace std;
    
    	int strength;
    	int endurance;
    	int dexterity;
    	int inteligence;
    	int stamina;
    	float health;
    	float essence;
    	float damageMultiplier;
    	float carryCapacity;
    	float critical;
    	float damageSkew;
    	
    int main()
    {
    	int atributes=0;
    	int assign=0;
    	string myFirstName("bob");
    	string myLastName("");
    	string space(" ");
    
    	cout<<"Character's first name? ";
    	cin>>myFirstName;
    	cout<<"Character's last name? ";
    	cin>>myLastName;
    	string myName=myFirstName+space+myLastName;
    	cout<<"\nyour name is "<<myName<<"?\n";
    
    	cout<<"there are 4 basic atributes. they are:\n1-strength\ndetermines your base damage and carry limit";
    	cout<<"\n2-endurance\ndetermines your health and stamina";
    	cout<<"\n3-dexterity\nreduces miss and mishap chance for all attacks and spells and increases critical chance";
    	cout<<"\n4-inteligence\ndetemines your essence and essence regeneration as well as spell effectiveness";
    	while(atributes<=3)
    	{
    	srand(static_cast<unsigned int>(time(0)));
    	int rolled=(rand()&#37;75+26);
    	while (rolled!=0)
    	{
    		cout<<"\nyou rolled a "<<rolled<<" what atribute do you want this assigned to"<<endl;
    		assign=0;
    		cin>>assign;
    	switch(assign)
    		{
    	case 1:
    		if(strength==0)
    			{
    			cout<<"you chose strength.";
    			strength=rolled;
    			++atributes;
    			rolled=0;
    			break;
    			}
    		else if (strength !=0)
    			{
    			cout<<"you already assigned strength. chose another.\n";
    			break;
    			}
    	case 2:
    		if(endurance==0)
    			{
    			cout<<"you chose endurance.";
    			endurance=rolled;
    			++atributes;
    			rolled=0;
    			break;
    			}
    		else if(endurance!=0)
    			{
    			cout<<"you already assigned endurance. chose another.\n";
    			break;
    			}
    	case 3:
    		if(dexterity==0)
    			{
    			cout<<"you chose dexterity.";
    			dexterity=rolled;
    			++atributes;
    			rolled=0;
    			break;
    			}
    		else if(dexterity!=0)
    			{
    			cout<<"you already assigned dexterity. chose another.\n";
    			break;
    			}
    	case 4:
    		if(inteligence==0)
    			{
    			cout<<"you chose inteligence.";
    			inteligence=rolled;
    			++atributes;
    			rolled=0;
    			break;
    			}
    		else if(inteligence!=0)
    			{
    			cout<<"you already chose inteligence. chose another.\n";
    			break;
    			}
    	default:
    			{
    			cout<<"thats not an option. chose another.\n";
    			break;
    			}
    		}
    		}
    	}
    	damageMultiplier=strength/10.0;
    	carryCapacity=(strength+endurance)*2.5;
    	stamina=endurance*1000.0;
    	essence=inteligence*(10.0-((100.0-inteligence)/100.0));
    	health=(stamina/10)+(essence/10);
    	critical=dexterity/5;
    	cout<<"\n"<<myName<<", ";
    	cout<<"your atributes are:\n";
    	cout<<"strength "<<strength<<"\n";
    	cout<<"endurance "<<endurance<<"\n";
    	cout<<"dexterity "<<dexterity<<"\n";
    	cout<<"inteligence "<<inteligence<<"\n";
    	cout<<"your basic abilities are:\n";
    	cout<<"health "<<health<<"\n";
    	cout<<"essence "<<essence<<"\n";
    	cout<<"stamina "<<stamina<<"\n";
    	cout<<"base damage multiplier "<<damageMultiplier<<"\n";
    	cout<<"Carry capacity "<<carryCapacity<<"\n";
    	cout<<"you will have a critical hit about %"<<critical<<"of the time.\n";
    	cout<<"wow, you suck at rolling. bye."<<endl;
    	return 0;
    }
    there are actualy two bugs I'm encountering in this code the first is that when the user puts in a value of an incorect type the program enters an infinite loop. the second bug is that when the user puts in a set of values seperated by spaces when prompted each one after the first is assigned to the next variable in the code.

    I Just started coding recently so if the errors seem self explanitory please explain them anyway. Also if this seems too low level for this site could you please recomend somewhere else I could find help.
    Last edited by Zeroandzerox; July 27th, 2011 at 12:13 PM. Reason: adding code tags

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center