How can I use GetUserInfo to get a user's age and name?

  • Topic:
  • Thread starter Thread starter Teh
  • Start date Start date
  • Tags Tags
    Function
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
1 reply · 7K views
Teh
Messages
47
Reaction score
0
I am not sure if should i use a for loop or if statement...may anyone give me a hint what i am suppose to do?Use function GetUserInfo to get a user's information. If user enters 20 and Holly, sample program output is:

Holly is 20 years old.
Code:
#include <iostream>
#include <string>
using namespace std;
void GetUserInfo(int& userAge, string& userName) {
   cout << "Enter your age: " << endl;
   cin >> userAge;
   cout << "Enter your name: " << endl;
   cin >> userName;
   return;
}
int main() {
   int userAge = 0;
   string userName = "";
   /* Your solution goes here  */
   
   cout << userName << " is " << userAge << " years old." << endl;
   return 0;
}
Testing with inputs 20 and Holly
Expected output: Holly is 20 years old.
Your output: is 0 years old.
 
Physics news on Phys.org
All you have to do is call [m]GetUserInfo[/m] with the appropriate parameters.