Write a C++ code which asks the user his/her info and then prints out the complete information in the following format:
Write a C++ code which asks the user his/her info and then prints out the complete information in the following format:
First Name:Last Name:
Gender: (Program will only accept M/F – Display error message if any other character entered) Occupation: Age:
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{ //variables
char gender;
string
first;
string
second;
string
third;
int age;
//input through user
cout<<"Enter first name";
getline
(cin,first);
cout<<"Enter second name";
getline
(cin,second);
cout<<"Enter your occupation";
getline
(cin,third);
cout<<"Enter your age";
cin>>age;
cout<<"Enter your gender (only
M/F (Note: Both M and F are capitals))";
cin>>gender;
if(gender=='M'||gender=='F')
{
cout<<"\nFirst Name:
"<<first<<endl;
cout<<"Last Name:
"<<second<<endl;
cout<<"Gender:
"<<gender<<endl;
cout<<"Occupation: "<<third<<endl;
cout<<"Age: "<<age<<endl;
}
else
{
cout<<"Wrong input"<<endl;
}
system("pause");
return 0;
}Output:
Comments
Post a Comment