Jump to content
  • Advertisement
Sign in to follow this  
RebornCrosis

My very fist Function I made in c++.

This topic is 4695 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#include <iostream>
using namespace std;


int UpgradeShop ( Hp , Defense , Agility , Intellegence , Dexerity , WillPower , Luck ){

cout << " Hello and welcome to my Shop.\n\n";
cout << " Is there anything That I can Intrest you in./n/n";
cout << " 1 - Hp Upgrade.\n";
cout << " 2 - Defense UpGrade.\n";
cout << " 3 - Agility.\n";
cout << " 4 - Intellegence.\n";
cout << " 5 - Dexerity.\n";
cout << " 6 - WillPower.\n";
cout << " 7 - Luck.\n";

int choice;
coout << " Choice.\n";
cin >> choice;

      switch ( choice ) {
case 1:
	cout << " Aye I see that you'r intrested in the Hpgrade.\n";
	cout << " It will cost 400 gold for 1 point if Hp.\n";
	cout << " Do you want to do this.\n";
	int choice;
	cout << " 1 - Yes.\n";
	cout << " 2 - No.\n";
	cin >> choice;

	if ( choice == 1 )
	{
		cout << " Ah thank you for the money.\n\n";
		Gold -= 400;
		cout << " Your Gold left after paying the man is " << Gold << endl;
		Hp += 1;
		cout << " Your Hp after the Upgrade is " << Hp << endl;
	}
		else 
			cout << " Please come again.\n";
		break;
case 2:
	cout << " Aye I see that you'r intrested in the Defense Upgrade.\n";
	cout << " That will be 600 gold, for 1 point of Defense.\n";
	cout << " Do you want to do this.\n";
	cout << " 1 - Yes.\n";
	cout << " 2 - No.\n";
	int choice2;
	cout << " Choice.\n";
	cin >> " choice2;
       
		if ( choice2 == 1 )
		{
           cout << " Ah thank you for the money!\n";
		   Gold -= 600;
		   cout << " Your Gold Left after paying the man is " << Gold << endl;
		   Defense += 1;
		   cout << " Your Defense after the Upgrade is " << Defense << endl;
		}
			else 
				cout << " Please come back when you have the Money.\n";
		break;
case 3;
	cout << " Aye I see that you'r intrested in the Agility Upgrade.\n";
	cout << " That will be 200 for, 1 point of Agility.\n";
	cout << " Do you want to do this?\n";
	cout << " 1 - Yes.\n";
	cout << " 2 - No.\n";
	int choice3;
	cout << " choice .\n";
	cin >> choice3;
    
		if ( choice == 3 )
		{
			cout << " Ah Thank you for the Money!\n";
			Gold -= 200;
			cout << " Your gold after paying the man is " << Gold << endl;
			Agility += 1;
			cout << " You'r Agility after the upgrade is << Agility << endl;
		}
			else
					cout << " Please come back when you have the money!\n";
			break;
case 4:
	cout << " Aye I see that you'r interested in the Intellegence Upgrade.\n";
	cout << " That will be 700 for 1 point of Intellegence.\n";
	cout << " Do you want to do this?\n";
	cout << " 1 - Yes.\n";
	cout << " 2 - No.\n";
	int choice4;
	cout << " Choice.\n";
	cin >> choice4;

		if ( choice4 == 1 )
		{
			cout << " Aye Thank you for the Money.\n";
			Gold -= 700;
			cout << " Your gold after paying the man is " << Gold << endl;
			Intellegence += 1;
			cout << " You Intellegence after the upgrade is " << Intellegence << endl;
		}
			else
				cout << " Please come back when u have the money.\n";
			break;
case 5:
	cout << " Aye I see that you are intrested in the Dexerity upgrade.\n";
	cout << " It will cost you 600 gold, for 1 point of Dexerity.\n";
	cout << " Do you wish to do this?\n";
	cout << " 1 - Yes.\n";
	cout << " 2 - No.\n";
	int choice5;
	cout << " Choice.\n";
	cin >> choice5;

		if ( choice5 == 1 )
		{
			cout << " Aye Thank you for the money.\n":
			Gold -= 600;
			cout << " Your gold after paying the man is " << Gold << endl;
			Dexerity += 1;
			cout << " You Decerity after the Upgrade is " << Dexerity << endl;
		}
			else 
				cout << " Please come back when u have the money.\n";
			break;
case 6:
	cout << " Aye I see that you are intrested in the willpower Upgrade.\n";
	cout << " It will cost 400 for, 1 point of willpower\n";
	cout << " Do you want to do this?\n";
	cout << " 1 - Yes.\n";
	cout << " 2 - No.\n";
	int choice6;
	cout << " Choice.\n";
	cin >> choice6;
		
		if ( choice6 == 1 )
		{
			cout << " Aye Thank you for the Money.\n";
			Gold -= 400;
			cout << " Your gold after paying the man is " << Gold << endl;
			WillPower += 1;
			cout << " Your WillPower after the upgrade is " << WillPower << endl;
		}
			else
				cout << " Please come back When you have the money.\n";
			break;
case 7:
	cout << " Aye I see that you are intrested in the Luck upgrade.\n";
	cout << " It will cost you 100 gold, for 1 point of Luck.\n";
	cout << " Do you want to do this?\n";
	cout << " 1 - Yes.\n";
	cout << " 2 - No.\n";
	int choice7;
	cout << " Choice.\n";
	cin >> choice7;
		
		if ( choice7 == 1 )
		{
			cout << " Aye Thank you for the Money.\n";
			Gold -= 100;
			cout << " Your gold after paying the man is " << Gold << endl;
			Luck += 1;
			cout << " Your Luck after upgrade is " << Luck << endl;
		}
			else 
				cout << " Please come back when you have the money.\n";
			break;
}
}
	return 0;
}



[Edited by - RebornCrosis on September 5, 2005 6:59:58 PM]

Share this post


Link to post
Share on other sites
Advertisement
The Function I made up, I took my switch/case soruce code and made it in to a function. It is my fist one so I might have done something wrong. Please comment on the function.

Share this post


Link to post
Share on other sites
Cool.

One piece of advice though, it would be much better to break that down into multiple functions. Another thing is to never do "using namespace std;". There is no need to bring every member of std:: into this scope. Just bring the things you need.

ace

Share this post


Link to post
Share on other sites
So when you say not use to use everthe hole std u mean like doing something like this?
using std::cout;
using std::cin;
using std::endl;

like that? Can i ask if i use the using namespace std; does it make the programe are fucntion run slower if it does not need to inlcude the hole std?

Share this post


Link to post
Share on other sites
nearly everyone uses using namespace std; In most cases there is no reason not to.

Arguments against it: you might have your own list type and don't want to conflict with std::list.

Why that is a bad argument: The standard library is such a central part of C++ that you simply should not use the same identifiers that it does. It will make your code confusing. I am not forced to type std::int, and so I should not be forced to type std::string. By using std you allow yourself to use strings and such in the same way that you use ints, which is one of the main strengths of C++.

Share this post


Link to post
Share on other sites
No it doesnt affect the speed or size of the program... Infact I've rarely seen it suggested even to bring in part of a namespace. Seems like a good way to waste time always adding more using's to the top of your code. I'd take a broad approach and just use all of std. Unless a naming conflict occurs. Then you could consider limiting what you import, however, a better solution would be to avoid the naming conflict all together.

For example, don't name your 3d vector class "vector" as this is the same as std::vector which is used for dynamically size arrays. Perhaps you could name yours Vector, or Vector3 instead. It's probably not a good idea to name your classes the same as things in the std namespace, even though you can, since it will just create problems and waste your time messing with using statements and naming conflicts.

Share this post


Link to post
Share on other sites
first of all, it's "whole std" not "hole std". to answer your question, not noticably. there's nothing wrong with 'using namespace std;' and i suggest you just keep using that. it works for your purposes, so just do it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!