You are here:

C++/Got some basic questions for ya


Hey, I'm learning C++ and I have a question.  I'd like to be able to jump around in parts of my code, repeat parts of the program as desired, etc.  What I have in mind is a RPGesque program-I've called it Quest for Awesome.  The player chooses which monster they want to fight, then they can fight the monster.  This part I've got programmed already.  The problem is, as the game is Quest for Awesome, I'd like the player to be able to collect awesome to make there be some point to the game aside from smacking down monsters.  I'm curious how I can take the variable of awesome from one function and retain it for all functions.  I'd also like to know how to return to int main after doing a different function-the idea being that the user chooses a monster, fights the monster, accumulates awesome, then returns to the main screen where they can see how much awesome they have and pick the next monster to fight.  I have absolutely no idea how to do this though.  My knowledge of C++ is very basic-I know the basic functions of the iostream library, and I can do looping, if statements, and use strings but that's about it, so go slow :)  Thanks!
BTW, in case it matters, the compiler I'm using is Turbo C++ by Boreland.  Also, I don't have a compiler at home, so if there are some free ones out there on the web you'd recommend, that'd be extra awesome for you :)

Hi there:
 I hope u'll be fine. For ur problems to be solved in a proper manner, u need to extend ur "basic knowledge" of c++ to atleast classes level. How to get a value from a function and retain it in other related funstions is a child's play (and in fact a part ) in object oriented programming(in object oriented programming, u use classes). It can also be done without using classes, but that would be non professional and inefficient too.
 Second problem: how to return to int main function. This can't be done. Any program starts executing from the main function and terminates when the main function ends. So to solve ur problem, u need to define another function, say
void StartGame()
that calls the other functions in the required sequence.
For example, ur StartGame function might look like

void StartGame()
DisplayStartScreen();//a fn. that displays the basic //interface of ur program

Now that u have this type of function, u just need to call this function again when ur player wants to restart the game by choosing a new monster.

About ur compiler problem, i really don't know any such sites. U may want to search on the popular search engines for the free download.

Plz. feel free to ask a followup, if u need to.
Thanks for contacting me


All Answers

Answers by Expert:

Ask Experts




I can answer any questions that range from the very basics of c++ to the advanced topics like polymorphism, inheritance, composition, multiple inheritance and templates. I can also answer almost every type of questions about c++ data structures like stack, queue, circular queue, linklist(single, double, circular), binary trees, binary search trees, avl trees, 2-3 and 2-3-4 trees. I dont have much experience of mfc and creating guis in visual c++, so plz. dont ask me questions about that.


I'm working in c++ since the last 6 years. I've good working skills specially in the advanced topics like inheritance, polymorphism and all type of c++ data structures.

©2017 All rights reserved.

[an error occurred while processing this directive]