In: Computer Science
C++
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.
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.
If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.
Thank You!
===========================================================================
#include<iostream>
#include<string>
using namespace std;
string getName(){
string fname;
cout<<"Please enter your first name: ";
cin >> fname;
return fname;
}
int getAge(){
int age;
cout<<"Enter your age: "; cin >>age;
return age;
}
int main(){
string firstName = getName();
int age = getAge();
cout<<"First Name entered: "
<<firstName<<endl;
cout<<"Age entered: "<<age;
return 0;
}
==================================================================