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

  • Thread starter Thread starter Teh
  • Start date Start date
  • Tags Tags
    Function
AI Thread Summary
The discussion revolves around using a function to retrieve user information and display it correctly. The function GetUserInfo is designed to take user input for age and name. The main issue highlighted is the need to call this function properly within the main program to ensure that the variables userAge and userName are populated with user input. The expected output format is specified, demonstrating that if the user inputs "20" for age and "Holly" for name, the program should output "Holly is 20 years old." The key takeaway is the importance of correctly invoking the GetUserInfo function with the right parameters to achieve the desired output.
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.
 
Technology news on Phys.org
All you have to do is call [m]GetUserInfo[/m] with the appropriate parameters.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top