User input
Moderator: Coders of Rage
-
- Chaos Rift Newbie
- Posts: 12
- Joined: Mon Feb 02, 2009 8:13 pm
User input
Hello my name is Erick and I've seen your youtube videos for the longest. Before i saw the videos i knew i was interested in video game design and development. I want to learn C++ and hopefully one day make a game engine! I bought a C++ book and im in like page 120 of 900 and everything was fine until when i wrote something like:
#include <iostream>
using namespace std;
int main();
{
Int hello;
cout <<"What is your name?";
cin >>hello;
cout <<"Hello " << hello <<" how was your day?" << endl;
system("pause");
return 0;
}
BEFORE everything worked fine but now in the output i would get something like this:
What is your name?
Hello 109992038 how was your day?
I GOT THOSE NUMBERS !
i have dev C++ (Bloodshed)
Please help and sorry if it was to long!
#include <iostream>
using namespace std;
int main();
{
Int hello;
cout <<"What is your name?";
cin >>hello;
cout <<"Hello " << hello <<" how was your day?" << endl;
system("pause");
return 0;
}
BEFORE everything worked fine but now in the output i would get something like this:
What is your name?
Hello 109992038 how was your day?
I GOT THOSE NUMBERS !
i have dev C++ (Bloodshed)
Please help and sorry if it was to long!
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: An Introduction to Programming, For beginners
Solution: use a string.
example:
this will fix it. Also you had a ';' at the end of the int main() line, so I removed it.
example:
Code: Select all
#include <iostream>
using namespace std;
int main()
{
string hello;
cout <<"What is your name?";
cin >>hello;
cout <<"Hello " << hello <<" how was your day?" << endl;
system("pause");
return 0;
}
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: An Introduction to Programming, For beginners
If ginto's solution doesn't work as-is, you'll need to "#include <string>" above or below "#include <iostream>"
The reason for your error is because variables of type "int" store numbers, not letters. Strings can store both, but you can't do math with strings, as it treats numbers in a string as letters, not as numbers you can do math with.
The reason for your error is because variables of type "int" store numbers, not letters. Strings can store both, but you can't do math with strings, as it treats numbers in a string as letters, not as numbers you can do math with.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
-
- Chaos Rift Newbie
- Posts: 12
- Joined: Mon Feb 02, 2009 8:13 pm
Re: An Introduction to Programming, For beginners
THANK YOU SO MUCH !!! YEAH IT DID WORK!
NOW I READ!
NOW I READ!
Re: An Introduction to Programming, For beginners
caps lock = cruise control for awesomeEvolutionXEngine wrote:THANK YOU SO MUCH !!! YEAH IT DID WORK!
NOW I READ!
it's true.
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: An Introduction to Programming, For beginners
Error: Invalid Logic.turb1ne wrote:caps lock = cruise control for awesomeEvolutionXEngine wrote:THANK YOU SO MUCH !!! YEAH IT DID WORK!
NOW I READ!
it's true.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: An Introduction to Programming, For beginners
ERROR: Stupidity::operator=(awesomeness) not foundturb1ne wrote:caps lock = cruise control for awesomeEvolutionXEngine wrote:THANK YOU SO MUCH !!! YEAH IT DID WORK!
NOW I READ!
it's true.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Re: An Introduction to Programming, For beginners
RAWFULL!!!!!!!Ginto8 wrote:ERROR: Stupidity::operator=(awesomeness) not foundturb1ne wrote:caps lock = cruise control for awesomeEvolutionXEngine wrote:THANK YOU SO MUCH !!! YEAH IT DID WORK!
NOW I READ!
it's true.
-
- Chaos Rift Newbie
- Posts: 12
- Joined: Mon Feb 02, 2009 8:13 pm
Re: An Introduction to Programming, For beginners
haha lol
string stupidity;
cout << "C'mon guys im just a noob, what's your name?";
cin >> stupidity;
cout << "C'mon guys im just a noob, my name is " << stupidity << " What is your name?";
system("pause");
return 0;
}
lol man this C++ book is hard!
string stupidity;
cout << "C'mon guys im just a noob, what's your name?";
cin >> stupidity;
cout << "C'mon guys im just a noob, my name is " << stupidity << " What is your name?";
system("pause");
return 0;
}
lol man this C++ book is hard!
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: An Introduction to Programming, For beginners
No fair you out C++'d me.Ginto8 wrote: ERROR: Stupidity::operator=(awesomeness) not found
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: An Introduction to Programming, For beginners
dandymcgee wrote:No fair you out C++'d me.Ginto8 wrote: ERROR: Stupidity::operator=(awesomeness) not found
You kinda missed my point. You'll have to wait until you get to operator overloading to understand.EvolutionXEngine wrote:haha lol
string stupidity;
cout << "C'mon guys im just a noob, what's your name?";
cin >> stupidity;
cout << "C'mon guys im just a noob, my name is " << stupidity << " What is your name?";
system("pause");
return 0;
}
lol man this C++ book is hard!
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Re: An Introduction to Programming, For beginners
Pfft, noobsGinto8 wrote:dandymcgee wrote:No fair you out C++'d me.Ginto8 wrote: ERROR: Stupidity::operator=(awesomeness) not found
You kinda missed my point. You'll have to wait until you get to operator overloading to understand.EvolutionXEngine wrote:haha lol
string stupidity;
cout << "C'mon guys im just a noob, what's your name?";
cin >> stupidity;
cout << "C'mon guys im just a noob, my name is " << stupidity << " What is your name?";
system("pause");
return 0;
}
lol man this C++ book is hard!
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: An Introduction to Programming, For beginners
not noobs, newbs.eatcomics wrote:Pfft, noobsGinto8 wrote:dandymcgee wrote:No fair you out C++'d me.Ginto8 wrote: ERROR: Stupidity::operator=(awesomeness) not found
You kinda missed my point. You'll have to wait until you get to operator overloading to understand.EvolutionXEngine wrote:haha lol
string stupidity;
cout << "C'mon guys im just a noob, what's your name?";
cin >> stupidity;
cout << "C'mon guys im just a noob, my name is " << stupidity << " What is your name?";
system("pause");
return 0;
}
lol man this C++ book is hard!
They're just new to this stuff, they're not the kind of person that is so annoying that they really piss you off.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: User input
Split from the 'Into to programming' sticky.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: User input
You missed one of my more useless posts towards the endMarauderIIC wrote:Split from the 'Into to programming' sticky.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!