• 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
Christopher Murray

Need help with an excercise from Beginning C++ 2nd edition

7 posts in this topic

The excerise is to write a program using vectors and iterators that allows a user to maintain a list of his or her favorite games. The program should allow the user to list all game titles, add games, and remove them.

Right now I'm working on adding the game titles, which I have figured out, however I want to loop it with a menu so that if the user hits 1, they can add another game, 2 they can remove a game, so on. So I figure to do this I need a loop, so I try a [i]do[/i] loop. However it's not allowing me to add ther part where I make the menu and get the input from the user, I'm assuming because I do not initialize the variable that holds the user's input, and if I initialize it, for example I tried to set it to 0 before getting input, it still didn't work. Perhaps I'm just trying to use the wrong loop? I don't quite understand [i]for [/i]loops unless I want the program to count for me.

Sorry for the block of text, just wanted to make clear what I'm having a problem with. Also I've only been into the book for about a week so a lot hasn't sunk in yet so the mistake may be obvious... Here's my code:

[code]//Program that allows a user to maintain a list of his or her favorite games.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> gameList;

vector<string>::iterator myIterator;
vector<string>::const_iterator iter;

do
{

unsigned short int options;
cout << "Select an option:\n";
cout << "1 - Add a game to your favorites list.\n";
cin >> options;

string game;


cout << "\nAdd a game to your favorites: ";
cin >> game;


gameList.insert(gameList.end(), game);

cout << "\nYour current list:\n";
for (iter = gameList.begin(); iter != gameList.end(); ++iter)
cout << *iter << endl;
} while (options == 1);

char theEnd;
cin >> theEnd;
return 0;
}[/code]

PS The variable theEnd is just there so the program doesn't automatically close. Using Dev-C++ and don't want to use .bat file every time I check a program, figured it'd be a simple way.
0

Share this post


Link to post
Share on other sites
First off let me say I have pretty basic knowledge of C++ and I'm pretty much a beginner in general, but my guess is if you want to do this what you need to do is have a way to escape the loop.

For example if your menu is

1 - Add Game
2 - Remove Game

You need to have something like:

9 - Quit

Then you can have your do loop do something like

do {
stuff;
}
while ( userAnswer != 9);
1

Share this post


Link to post
Share on other sites
[quote name='Christopher Murray' timestamp='1329271350' post='4913215']
PS The variable theEnd is just there so the program doesn't automatically close. Using Dev-C++ and don't want to use .bat file every time I check a program, figured it'd be a simple way.
[/quote]
Dev-C++ is years old, although I think someone's forked a newer IDE from it. I'd strongly recommend MSVC Express. It's quality software and it's free. If you're absolutely against Microsoft then there's Code::Blocks, also free. I'd provide links if I weren't on my phone, but Google is your friend.

I've never seen anyone recommend Dev-C++ for any reason.
1

Share this post


Link to post
Share on other sites
a do-while loop would be fine in this case, but your check after the while is the problem:
[code]
do
{
int options;
cout << "Select an option:\n";
cout << "1 - Add a game to your favorites list.\n";
cout << "2 - Remove a game to your favorites list.\n";
cout << "3 - List all games.\n"
cout << "0 - Quit program.\n"
cin >> options;

if (option = 1) {
string game;

cout << "\nAdd a game to your favorites: ";
cin >> game;

gameList.push_back(game);
}
else if ... // check all other options

} while (options != 0);
[/code]
1

Share this post


Link to post
Share on other sites
[quote name='Christopher Murray' timestamp='1329334262' post='4913438']
Thank you everyone, got it working now = )
[/quote]
You're welcome.
1

Share this post


Link to post
Share on other sites
As a little addition, you can use functions for each option:
[code]
void add()
{
// Print out the add message and get the input
// Push the input onto the vector
}
void remove()
{
// Print out the remove message and get the input
// Pop the input off the vector
}
void view()
{
// Print the vector with iterators
}

int main()
{
int optionChoice = 0;
do
{
view();
// Get input choice and set to optionChoice;
switch(optionChoice)
{
case 1:
add();
break;
case 2:
remove();
break;
default:
break;
}
} while(optionChoice != 3);
return 0;
}[/code]
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