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

  • MHB
  • Thread starter Teh
  • Start date
  • Tags
    Function
This will prompt the user to enter their age and name, and then assign those values to the variables userAge and userName. Then, you can simply output the variables in the desired format. In summary, to get a user's information and display it, you should use the function GetUserInfo and output the user's name and age in the correct format.
  • #1
Teh
47
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
  • #2
All you have to do is call [m]GetUserInfo[/m] with the appropriate parameters.
 

What is the purpose of using an existing function?

The purpose of using an existing function is to save time and effort by utilizing a pre-written block of code that performs a specific task. This can help streamline the coding process and reduce the chances of errors.

How do I find an existing function to use?

You can find existing functions in a variety of ways, such as searching online for code libraries, using documentation for programming languages or software, or collaborating with other programmers who may have already written the function you need.

Can I modify an existing function to fit my specific needs?

Yes, many existing functions are designed to be customizable and can be modified to fit your specific requirements. However, it is important to understand the function's purpose and how it is written before attempting to modify it.

What are the potential drawbacks of using an existing function?

One potential drawback is that the function may not be compatible with your specific programming language or software. Another drawback is that the function may not perform exactly as desired and may require additional modifications. Additionally, using too many existing functions can make the codebase more complex and difficult to debug.

How can I ensure the reliability and security of an existing function?

Before using an existing function, it is important to research its source and ensure that it comes from a reputable and trusted source. Additionally, thoroughly testing the function and checking for any potential vulnerabilities can help ensure its reliability and security.

Similar threads

  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
15
Views
2K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
6
Views
8K
  • Programming and Computer Science
2
Replies
66
Views
4K
  • Programming and Computer Science
Replies
3
Views
734
Replies
10
Views
961
  • Programming and Computer Science
Replies
8
Views
2K
Back
Top