• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
WunderStrudel

Need help with "Calling"

8 posts in this topic

Hi guys (: 

I'm kinda new to C++ , just started today so bare with me d; 

I made a Calculator from a tutorial, and after that i used my knowledge of python and normal logic to write this piece of code. 

#include <string>
#include <iostream>
using namespace std;


int main()
{

	string lBrugerNavn, lPassword;
	cout << "Brugernavn: ";
	cin >> lBrugerNavn; 
	cout << endl;
	cout << "Password: ";
	cin >> lPassword;
	if (lBrugerNavn == "Jokke"
		&& lPassword == "1234")
	{
		system("CLS");
		menu();
	}
	else 
	{
		cout << "Bad Logon. Try again!" << endl;
		system("CLS");
		main();
	}
	cin.get();
	cin.get();


}

int menu()
{
	string lBrugerNavn, Choice;
	cout << "Welcome" << lBrugerNavn;
	cout << endl;
	cout << endl;
	cout <<"1 - Calculator" << endl;
	cout << endl;
	cout <<"2 - Random Option" << endl;
	cout << endl;
	cout <<"3 - Random Option" << endl;
	cout << endl;
	cout <<"4 - Random Option" << endl;
	cout << endl;
	cin >> Choice;
	if (Choice == 1)
		claculator();
	else if (Choice == 2)
		randomoption();
}

int calculator()
{

}

I know that the top part is working, but my problem is "Calling" the "Menu" after login passed.

i dont really know if my menu is gonna work yet, cos i cant relly test it before getting the "Calling" working d: 

I hope there is somebody out there with a fix, i'm on a steep learning curve here :D 

0

Share this post


Link to post
Share on other sites

 The compiler needs to know what 'menu()' is. Basically you 'forward declare' it before your main() function. Something like "int menu();" before the "int main() { ... }" should do the trick. Same goes for the other functions that you call before they appear in the source code. 

 

edit: this should probably be in the 'for beginners' forum.

Edited by bradbobak
0

Share this post


Link to post
Share on other sites


edit: this should probably be in the 'for beginners' forum.

 

Thanks for you post (: 
And yeah maybe, though the beginner forum was more generel question than coding questions, and didn't wanna place it in the wrong forum d; 

And well, i'm not rly sure i understand what you mean with the "Calling" can you make a quick line of code, with your ex. or something? Thanks a lot on advance mate (: 

0

Share this post


Link to post
Share on other sites

Copy the menu function above the main function. Basically the compiler is starting at the very top of your file... coming down to main, then seeing the call to menu() and going "I have no idea what this function is", if you had the menu function at the top of the page (below the includes and namespace) then the compiler would have already seen the function before it got to it in main, and therefore it would know what it was.

 

bradbobak suggested just writing the line "int menu();" before main(), that would say to the compiler "There is a function called menu, I'm not going to tell you what it does yet, but just know if you see it in main() then all will be explained later on." smile.png

 

Also you may want to correct the spelling of 'calculator()' after (Choice==1) in the menu function.

Edited by Godmil
0

Share this post


Link to post
Share on other sites


Copy the menu function above the main function. Basically the compiler is starting at the very top of your file... coming down to main, then seeing the call to menu() and going "I have no idea what this function is", if you had the menu function at the top of the page (below the includes and namespace) then the compiler would have already seen the function before it got to it in main, and therefore it would know what it was.

Thanks alot man! :D 

 


Also you may want to correct the spelling of 'calculator()' after (Choice==1) in the menu function.

Haha i will d; 

0

Share this post


Link to post
Share on other sites

You are still calling main() from inside main(). That should be an error - it is illegal in C++ to call main recursively. If you want the stuff inside main to repeat endlessly wrap it in a for(;;) or while(true) loop.

1

Share this post


Link to post
Share on other sites

You are still calling main() from inside main(). That should be an error - it is illegal in C++ to call main recursively. If you want the stuff inside main to repeat endlessly wrap it in a for(;;) or while(true) loop.

 

I was pretty impressed by the recursion there. If you fail the logon repeatedly it continues to accumulate cin.get() calls for when the program finally exits.

0

Share this post


Link to post
Share on other sites

 

You are still calling main() from inside main(). That should be an error - it is illegal in C++ to call main recursively. If you want the stuff inside main to repeat endlessly wrap it in a for(;;) or while(true) loop.

 

I was pretty impressed by the recursion there. If you fail the logon repeatedly it continues to accumulate cin.get() calls for when the program finally exits.

 

 

Well you could throw and catch an exception to avoid that ;) A DoS attack is going to make the stack overflow though ;)

 

The reason you aren't allowed to call main recursively is because main can do extra work such as call constructors for global/static objects if the compiler implementer feels like it... all compilers I have used do that before main is actually called though.

 

It's allowed in C unless they have also banned it now.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0