User input

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
EvolutionXEngine
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 12
Joined: Mon Feb 02, 2009 8:13 pm

User input

Post by EvolutionXEngine »

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!
User avatar
Ginto8
ES Beta Backer
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

Post by Ginto8 »

Solution: use a string.

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;
}
this will fix it. Also you had a ';' at the end of the int main() line, so I removed it.
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.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: An Introduction to Programming, For beginners

Post by MarauderIIC »

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.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
EvolutionXEngine
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 12
Joined: Mon Feb 02, 2009 8:13 pm

Re: An Introduction to Programming, For beginners

Post by EvolutionXEngine »

THANK YOU SO MUCH !!! YEAH IT DID WORK!

NOW I READ!
turb1ne
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 1
Joined: Wed Feb 04, 2009 10:47 am

Re: An Introduction to Programming, For beginners

Post by turb1ne »

EvolutionXEngine wrote:THANK YOU SO MUCH !!! YEAH IT DID WORK!

NOW I READ!
caps lock = cruise control for awesome

it's true.
User avatar
dandymcgee
ES Beta Backer
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

Post by dandymcgee »

turb1ne wrote:
EvolutionXEngine wrote:THANK YOU SO MUCH !!! YEAH IT DID WORK!

NOW I READ!
caps lock = cruise control for awesome

it's true.
Error: Invalid Logic.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
Ginto8
ES Beta Backer
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

Post by Ginto8 »

turb1ne wrote:
EvolutionXEngine wrote:THANK YOU SO MUCH !!! YEAH IT DID WORK!

NOW I READ!
caps lock = cruise control for awesome

it's true.
ERROR: Stupidity::operator=(awesomeness) not found
:lol:
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.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: An Introduction to Programming, For beginners

Post by eatcomics »

Ginto8 wrote:
turb1ne wrote:
EvolutionXEngine wrote:THANK YOU SO MUCH !!! YEAH IT DID WORK!

NOW I READ!
caps lock = cruise control for awesome

it's true.
ERROR: Stupidity::operator=(awesomeness) not found
:lol:
RAWFULL!!!!!!!
Image
EvolutionXEngine
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 12
Joined: Mon Feb 02, 2009 8:13 pm

Re: An Introduction to Programming, For beginners

Post by EvolutionXEngine »

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!
User avatar
dandymcgee
ES Beta Backer
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

Post by dandymcgee »

Ginto8 wrote: ERROR: Stupidity::operator=(awesomeness) not found
:lol:
No fair you out C++'d me. :|
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
Ginto8
ES Beta Backer
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

Post by Ginto8 »

dandymcgee wrote:
Ginto8 wrote: ERROR: Stupidity::operator=(awesomeness) not found
:lol:
No fair you out C++'d me. :|
:lol:
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!
:roll: You kinda missed my point. You'll have to wait until you get to operator overloading to understand. ;)
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.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: An Introduction to Programming, For beginners

Post by eatcomics »

Ginto8 wrote:
dandymcgee wrote:
Ginto8 wrote: ERROR: Stupidity::operator=(awesomeness) not found
:lol:
No fair you out C++'d me. :|
:lol:
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!
:roll: You kinda missed my point. You'll have to wait until you get to operator overloading to understand. ;)
Pfft, noobs :lol:
Image
User avatar
Ginto8
ES Beta Backer
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

Post by Ginto8 »

eatcomics wrote:
Ginto8 wrote:
dandymcgee wrote:
Ginto8 wrote: ERROR: Stupidity::operator=(awesomeness) not found
:lol:
No fair you out C++'d me. :|
:lol:
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!
:roll: You kinda missed my point. You'll have to wait until you get to operator overloading to understand. ;)
Pfft, noobs :lol:
not noobs, newbs. :lol:

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.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: User input

Post by MarauderIIC »

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.
User avatar
dandymcgee
ES Beta Backer
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

Post by dandymcgee »

MarauderIIC wrote:Split from the 'Into to programming' sticky.
You missed one of my more useless posts towards the end :)
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Post Reply