Page 1 of 1

User input

Posted: Mon Feb 02, 2009 8:35 pm
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!

Re: An Introduction to Programming, For beginners

Posted: Mon Feb 02, 2009 8:39 pm
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.

Re: An Introduction to Programming, For beginners

Posted: Mon Feb 02, 2009 9:02 pm
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.

Re: An Introduction to Programming, For beginners

Posted: Tue Feb 03, 2009 4:47 pm
by EvolutionXEngine
THANK YOU SO MUCH !!! YEAH IT DID WORK!

NOW I READ!

Re: An Introduction to Programming, For beginners

Posted: Wed Feb 04, 2009 10:53 am
by turb1ne
EvolutionXEngine wrote:THANK YOU SO MUCH !!! YEAH IT DID WORK!

NOW I READ!
caps lock = cruise control for awesome

it's true.

Re: An Introduction to Programming, For beginners

Posted: Wed Feb 04, 2009 8:05 pm
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.

Re: An Introduction to Programming, For beginners

Posted: Wed Feb 04, 2009 9:30 pm
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:

Re: An Introduction to Programming, For beginners

Posted: Wed Feb 04, 2009 9:59 pm
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!!!!!!!

Re: An Introduction to Programming, For beginners

Posted: Thu Feb 05, 2009 10:34 am
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!

Re: An Introduction to Programming, For beginners

Posted: Thu Feb 05, 2009 2:54 pm
by dandymcgee
Ginto8 wrote: ERROR: Stupidity::operator=(awesomeness) not found
:lol:
No fair you out C++'d me. :|

Re: An Introduction to Programming, For beginners

Posted: Thu Feb 05, 2009 4:53 pm
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. ;)

Re: An Introduction to Programming, For beginners

Posted: Fri Feb 06, 2009 8:37 pm
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:

Re: An Introduction to Programming, For beginners

Posted: Fri Feb 06, 2009 8:44 pm
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. ;)

Re: User input

Posted: Thu Mar 12, 2009 3:27 pm
by MarauderIIC
Split from the 'Into to programming' sticky.

Re: User input

Posted: Thu Mar 12, 2009 6:51 pm
by dandymcgee
MarauderIIC wrote:Split from the 'Into to programming' sticky.
You missed one of my more useless posts towards the end :)