- 2
im having challenge with this code
#include <iostream> using namespace std; int main() { char Fname,Lname,email,address,contact; cout << "Enter your First name "; cin>>Fname; cout << "Enter your Last name "; cin>>Lname; cout << "Enter your email "; cin>>email; cout << "Enter your address "; cin>>address; cout << "Enter your contact "; cin>>contact; cout << "Your full name is "<<Fname<<" "<<Lname<<" with an email address "<<email<<"with address "<<address<<"and your contact number is "<<contact<<endl; return 0; }
7 ответов
0
what's wrong with the code? i cant see anything wrong about the code so please specify what the problem or challenge is.
0
It's fine code but you declared all variables as char only so it accept only single char..
Edit:
(use charecter array for taking strings).
Ex:
For string accept for Fname, use
char* Fname or char[] Fname.
0
The output "enter your address", enter your contact" shows on the same line.. it doesn't give me the opportunity to input them seperetely
0
You can use endl or \n to come to new line like
cout<<"enter your address\n";
cin>>address;
One more point, that cin accept only one word.. It stops reading after space or new line encounters...
0
can I use getline for all the input like
Fname, Lname, address, and contact
0
Yes.
To take a line of string, use getline. If it single line, cin enough..
You can use it for all but enter input separate lines..
I forget to add it in previous post.
0
ok.. its working now. Thank you very much