Write a program that declares two variables: a string firstName and int age. Wri
ID: 3720710 • Letter: W
Question
Write a program that declares two variables: a string firstName and int age. Write a function, called getName, that when called, prompts the user for their first name. The function should return the first name and store it in the firstName variable. Write a function, called getAge, that when called, prompts the user for their age. The function should return the age and store it in the age variable. Write a function, that uses the firstName and age as arguments. In the function, print out the person's name and age.Explanation / Answer
#include <iostream>
using namespace std;
string getName() {
string name;
cout<<"Enter the first name: "<<endl;
cin >> name;
return name;
}
int getAge() {
int age;
cout<<"Enter the age: "<<endl;
cin >> age;
return age;
}
void printData(string firstName,int age) {
cout<<"First Name: "<<firstName<<endl;
cout<<"Age: "<<age<<endl;
}
int main()
{
string firstName;
int age;
firstName= getName();
age = getAge();
printData(firstName, age);
return 0;
}
Output:
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.