• 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
patisake

strange occurence mittle piecec++ code I wrote

10 posts in this topic

Hello everybody,

I have started with studying C++ and it goes very well since I never have learned a program language. I studied from the e-book juming into C++ which is a very good ebook for beginners.

Now I have wrote a piece of code and when I put in the numbers it is going good. But <hen I do a test and as a first number or in dutch type eerste number and then an a or b I get a very strange result..Can somebody explain why he is doing that?

So I learn more about behavour of C++ I have wrote the code in orwell devC++

the code is:


#include <iostream>
using namespace std;
int main ()
{
int eerste_liefdes_nummer;
int tweede_liefdes_nummer;

cout << "type eerste liefdes nummer: ";
cin>> eerste_liefdes_nummer;
cout << "type tweede liefdes nummer: ";
cin>>tweede_liefdes_nummer;
cout << eerste_liefdes_nummer << " * " << tweede_liefdes_nummer << " = " << eerste_liefdes_nummer * tweede_liefdes_nummer << endl;
cout << "jullie zijn heel erg verliefd";
}



Patrick
0

Share this post


Link to post
Share on other sites
Do you mean you literally type "a" or "b" instead of a number?

If that's the case, then your input fails because a number is expected. Let's say you type "a" letter instead of a number for the first number. The input is incorrect and the input fails, leaving the first variable unchanged and leaving the letter "a" in the input stream. When reaching the second input, the input stream still contains the letter "a" and you're trying to read the second number. This also fails, leaving the second variable unchanged, and again leaving the letter "a" in the input stream.

Now you have to variables with no particular value, and you proceed to print them.
0

Share this post


Link to post
Share on other sites
Als eerste welkom hier.

What you ran into happens because you don't initialise:
[code]int eerste_liefdes_nummer;
int tweede_liefdes_nummer;[/code]

In C++ when you don't initialise a variable it will just contain random data, or to put this a bit more correctly just the data the that's in the location assigned to the variable.
0

Share this post


Link to post
Share on other sites
no, it does the following thing otherwise paste the code and test it....

type eerste liefdes nummer: a (I type a instead of a number and press enter)

the result is:type tweede liefdesnummer: 0 * 49 = 0 (that is what it puts on the screen after the enter of the first a

nightcreature..are you speaking dutch?spreek je nederlands?
0

Share this post


Link to post
Share on other sites
I dont know whats wrong but ill just list what i understood the problem to be:
1.You type "a" for the first number
2.You press enter

then it:
-completely skips waiting for the second number
-puts 49 in the second number, not the first number where it should be?
-tells you what they are multiplied (with the first number 0)
0

Share this post


Link to post
Share on other sites
I forgot to mention this, but a common shortcut for reading a value from a stream and checking it succeeded is to place the read operation as the conditional expression:

For example:
[code]
if(cin >> someVariable) {
// We read someVariable!
}

// or

while(getline(cin, line)) {
// we read a line!
}
[/code]
1

Share this post


Link to post
Share on other sites
What does it return? Char count? [/lazymode]

Nvm, I looked it up. Returns .good(). Nice to know. Edited by Khatharr
0

Share this post


Link to post
Share on other sites
Robust input from the user is surprisingly hard to do, as you can probably gather from rip-off's post. I rarely write programs where the user types anything in (my programs read command-line options and configuration files instead) but when I do, I always read the input line by line with `std::getline(std::cin, line)' and then parse the line. In my experience it's the safest way to do things.

Since you are a beginner, it is likely that rip-off's code is too complicated for you at this stage. If that's the case, skip this whole robust-input thing and get on with learning the basics of the language (just be careful when you type ;) ). Once you are more comfortable with the language, come back and read his very useful code.
1

Share this post


Link to post
Share on other sites
[quote name='patisake' timestamp='1352898995' post='5000897'] no, it does the following thing otherwise paste the code and test it.... type eerste liefdes nummer: a (I type a instead of a number and press enter) the result is:type tweede liefdesnummer: 0 * 49 = 0 (that is what it puts on the screen after the enter of the first a nightcreature..are you speaking dutch?spreek je nederlands? [/quote]

Ja, ik spreek Nederlands woon er alleen niet meer.

[quote name='Álvaro' timestamp='1352905742' post='5000926'] Robust input from the user is surprisingly hard to do, as you can probably gather from rip-off's post. I rarely write programs where the user types anything in (my programs read command-line options and configuration files instead) but when I do, I always read the input line by line with `std::getline(std::cin, line)' and then parse the line. In my experience it's the safest way to do things. Since you are a beginner, it is likely that rip-off's code is too complicated for you at this stage. If that's the case, skip this whole robust-input thing and get on with learning the basics of the language (just be careful when you type ;) ). Once you are more comfortable with the language, come back and read his very useful code. [/quote]
I found using JSON or XML parsers to be easier then using ini or text files. Also gives you the ability of skipping whole blocks if the code doesn't understand the content.
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