Help Please!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Help Please!!

Hello, This is my code for C++. #include <iostream> using namespace std; int main() { string name; int age; string Lname; cout << "Enter your name" << endl; cin >> name; cout << "Enter your last name" << endl; cin >> Lname; cout << "Enter your age" << endl; cin >> age; } It only shows the Enter your age, enter your last name, and first name and not your actual details. Please Help

5th Jun 2018, 12:33 AM
Sai Manikandan
Sai Manikandan - avatar
11 Answers
+ 8
You only asked for the input of first name, last name and age.. You never printed the output (cout) for first name, last name and age... You just need to add three cout's for displaying it...Sai Manikandan
6th Jun 2018, 2:58 PM
$hardul B
$hardul B - avatar
+ 7
#include <iostream> using namespace std; int main() { string name; int age; string Lname; cout << "Enter your name" << endl; cin >> name; cout<<name<<endl; cout << "Enter your last name" << endl; cin >> Lname; cout<<Lname<<endl; cout << "Enter your age" << endl; cin >> age; cout<<age<<endl; }
5th Jun 2018, 1:17 AM
Yusuf
Yusuf - avatar
+ 6
Yes
5th Jun 2018, 1:18 AM
Yusuf
Yusuf - avatar
+ 3
In your code, it seems that you're only trying to receive and store a value from the user, which by itself is not enough to output it. To actually print the data, you would have to add a separate cout statement specifically for printing out the value given by the user.
5th Jun 2018, 12:44 AM
Faisal
Faisal - avatar
+ 3
So basically, I would do like cout << name << Lname << age; ?
5th Jun 2018, 1:18 AM
Sai Manikandan
Sai Manikandan - avatar
+ 2
Sai Manikandan Make sure that you're placing that line after you've received all your input, so right around the end of the code. For Joseph Hardrock 's code, it seems to work fine for me. If you're not doing it, try pressing the enter key in between each input to individualize all of them and make sure that they go to the right variable.
5th Jun 2018, 2:48 AM
Faisal
Faisal - avatar
+ 1
If you are trying to take more than 1 word to a variable then the program will fail. You need to use getline function to take a sentence from the user. Here is the working example of the above program: https://code.sololearn.com/cXURw7YJGygd/?ref=app
5th Jun 2018, 8:54 AM
Yusuf
Yusuf - avatar
+ 1
OK got it thx.
6th Jun 2018, 1:24 AM
Sai Manikandan
Sai Manikandan - avatar
0
Apparently, it is showing some error as I put it in.
5th Jun 2018, 2:39 AM
Sai Manikandan
Sai Manikandan - avatar
0
Joseph, your code shows up as an error on my output screen. I know that the code is right but something is wrong.
5th Jun 2018, 2:45 AM
Sai Manikandan
Sai Manikandan - avatar
0
cout << name ; cout << Lname ; cout << age ;
5th Jun 2018, 5:10 AM
Aveek Bhattacharyya
Aveek Bhattacharyya - avatar