+ 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
11 Antworten
+ 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
+ 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;
}
+ 6
Yes
+ 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.
+ 3
So basically, I would do like cout << name << Lname << age; ?
+ 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.
+ 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
+ 1
OK got it thx.
0
Apparently, it is showing some error as I put it in.
0
Joseph, your code shows up as an error on my output screen. I know that the code is right but something is wrong.
0
cout << name ;
cout << Lname ;
cout << age ;