So I'm making a text based adventure in C++ and I'm doing this all fabulously when suddenly I realize I don't know how to output infomation that the user gave.
#include "stdafx.h"
int name;
int _tmain(int argc, _TCHAR* argv[])
{
printf("I hope you're prepared to enter the world lying beneath the kettle lid\n");
printf("This is a text based adventure game created based on the imagination of young \n");
printf("Sam Downey. As you walk around in this world you will have to choose your own\n");
printf("path and if you're lucky you might even get to met Ms Downey yourself, though\n");
printf("she is a busy programmer and might just shake your hand in the end (but the \n");
printf("more you impress her the better chance you'll have of meeting Samantha ;D)\n\n");
printf("So if you are ready to begin the adventure, please enter your name here.");
scanf("%d", name); //The name of the users charactor
if ( name )
{
printf();
}
scanf("pause");
return 0;
}
If I did it correct then the user's answer should have stored their name into the int name;
So my question is how do I make it so the given name is put in the printf(); Dialogue. Sorry if I don't make since or sound stupid. And tell me if I did something wrong.
First and foremost, unless your user is a computer that only has a number for a name, you're going to get a problem with type casting. Others may point out other problems, but that is going to be a big one. String, or a char[], but not int.
Btw, do you know C++ basics? If not, please go for a quick tutorial.
char name[64] is a cstring (character array) of 64 characters. Since you are not familiar with strings and cannot use iostream, you're left with cstrings. And, when declaring a cstring, you need to include the number of characters it can hold.
Well, no offense but the fact that you declared your characters name as an integer means you might want to go through some basic tutorials again. I think you're missing out on a very fundamental concept here. Come up to speed on C++ I/O too. printf and scanf are plain old C commands. C++ has better options. The tutorial on this site is quick and should bring you up to speed: http://cplusplus.com/doc/tutorial/