162k views
0 votes
Write a program which asks the user his/ her last name, stores it in a variable called lname, then asks What is your age? and stores it in a variable called age. After this, the program displays a userid, for example as follows: What is your last name? Jones What is your age? 20 Your user id is: Jones20

1 Answer

1 vote

Answer:

// program in C++.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// variables

int age;

string lname;

cout<<"Enter your last name:";

// read last name

cin>>lname;

cout<<"Enter your age:";

// read age

cin>>age;

// print user id

cout<<"Your user id is: "<<lname<<" "<<age<<endl;

return 0;

}

Step-by-step explanation:

Read last name from user and assign it to variable "lname".Then read age from user and assign it to variable "age".After this print the user id as last name followed by age.

Output:

Enter your last name:singh

Enter your age:24

Your user id is: singh 24

User Chmike
by
4.2k points