You are viewing our Forum Archives. To view or take place in current topics click here.
can somebody please help me with this simple program? c++
Posted:

can somebody please help me with this simple program? c++Posted:

UK_cHaDd3rZ
  • Ladder Climber
Status: Offline
Joined: Sep 05, 201212Year Member
Posts: 384
Reputation Power: 14
Status: Offline
Joined: Sep 05, 201212Year Member
Posts: 384
Reputation Power: 14
its c++ and when i build and run it asks the user, what is your name?
user inputs name, example josh
then the cmd puts a line of dots .........
then its meant to say user input(josh) is a cool name dude but instead it says 0is a cool name dude. is this because i have return 0; at the end and im returning a value?


#include <iostream>
using namespace std;
int userinput;
int main (){
cout << "what is your name? \n";
cin >> userinput;
cout << "........." << endl;
cout << userinput << "is a cool name dude \n";
return 0;

}


Last edited by UK_cHaDd3rZ ; edited 1 time in total
#2. Posted:
Imp
  • Blind Luck
Status: Offline
Joined: Jan 01, 201114Year Member
Posts: 1,957
Reputation Power: 401
Status: Offline
Joined: Jan 01, 201114Year Member
Posts: 1,957
Reputation Power: 401
UK_cHaDd3rZ wrote #include <iostream>

its c++ and when i build and run it asks the user, what is your name?
user inputs name, example josh
then the cmd puts a line of dots .........
then its ment to say user input(josh) is a cool name dude but instead it says 0is a cool name dude. is this because i have return 0; at the end and im returning a value?



using namespace std;
int userinput;
int main (){
cout << "what is your name? \n";
cin >> userinput;
cout << "........." << endl;
cout << userinput << "is a cool name dude \n";
return 0;

}


You have put the variable userinput as data type int. this needs to be string (with a small s)
#3. Posted:
UK_cHaDd3rZ
  • Ladder Climber
Status: Offline
Joined: Sep 05, 201212Year Member
Posts: 384
Reputation Power: 14
Status: Offline
Joined: Sep 05, 201212Year Member
Posts: 384
Reputation Power: 14
Imp wrote
UK_cHaDd3rZ wrote #include <iostream>

its c++ and when i build and run it asks the user, what is your name?
user inputs name, example josh
then the cmd puts a line of dots .........
then its ment to say user input(josh) is a cool name dude but instead it says 0is a cool name dude. is this because i have return 0; at the end and im returning a value?



using namespace std;
int userinput;
int main (){
cout << "what is your name? \n";
cin >> userinput;
cout << "........." << endl;
cout << userinput << "is a cool name dude \n";
return 0;

}


You have put the variable userinput as data type int. this needs to be string (with a small s)

i dont understand , it is an int userinput; please could you show me what you mean on the last line? thanks for the help.
#4. Posted:
Imp
  • Blind Luck
Status: Offline
Joined: Jan 01, 201114Year Member
Posts: 1,957
Reputation Power: 401
Status: Offline
Joined: Jan 01, 201114Year Member
Posts: 1,957
Reputation Power: 401
UK_cHaDd3rZ wrote
Imp wrote
UK_cHaDd3rZ wrote #include <iostream>

its c++ and when i build and run it asks the user, what is your name?
user inputs name, example josh
then the cmd puts a line of dots .........
then its ment to say user input(josh) is a cool name dude but instead it says 0is a cool name dude. is this because i have return 0; at the end and im returning a value?



using namespace std;
int userinput;
int main (){
cout << "what is your name? \n";
cin >> userinput;
cout << "........." << endl;
cout << userinput << "is a cool name dude \n";
return 0;

}


You have put the variable userinput as data type int. this needs to be string (with a small s)

i dont understand , it is an int userinput; please could you show me what you mean on the last line? thanks for the help.


You want the variable userinput to hold a name (which is a string of characters) and you have told the compiler that userinput is an int (integer, a number)

Instead of

int userinput;

you put

string userinput;

Check out Data types here [ Register or Signin to view external links. ]
#5. Posted:
UK_cHaDd3rZ
  • Ladder Climber
Status: Offline
Joined: Sep 05, 201212Year Member
Posts: 384
Reputation Power: 14
Status: Offline
Joined: Sep 05, 201212Year Member
Posts: 384
Reputation Power: 14
Imp wrote
UK_cHaDd3rZ wrote
Imp wrote
UK_cHaDd3rZ wrote #include <iostream>

its c++ and when i build and run it asks the user, what is your name?
user inputs name, example josh
then the cmd puts a line of dots .........
then its ment to say user input(josh) is a cool name dude but instead it says 0is a cool name dude. is this because i have return 0; at the end and im returning a value?



using namespace std;
int userinput;
int main (){
cout << "what is your name? \n";
cin >> userinput;
cout << "........." << endl;
cout << userinput << "is a cool name dude \n";
return 0;

}


You have put the variable userinput as data type int. this needs to be string (with a small s)

i dont understand , it is an int userinput; please could you show me what you mean on the last line? thanks for the help.


You want the variable userinput to hold a name (which is a string of characters) and you have told the compiler that userinput is an int (integer, a number)

Instead of

int userinput;

you put

string userinput;

Check out Data types here [ Register or Signin to view external links. ]

oh right i understand now, im such a dummie at times. cheers for the help.
#6. Posted:
DimiPro
  • TTG Senior
Status: Offline
Joined: Oct 18, 201113Year Member
Posts: 1,200
Reputation Power: 48
Status: Offline
Joined: Oct 18, 201113Year Member
Posts: 1,200
Reputation Power: 48
#include <iostream>
using namespace std;
string userinput;
int main (){
cout << "what is your name? \n";
cin >> userinput;
cout << "........." << endl;
cout << userinput << "is a cool name dude \n";
return 0;

}
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.