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
Click For Summary
SUMMARY

The discussion focuses on using the function GetUserInfo in C++ to retrieve a user's age and name. Participants clarify that the function should be called correctly within the main function to store user input. The expected output format is confirmed as " is years old." The key takeaway is that the function must be invoked with the correct parameters to ensure the program outputs the desired result.

PREREQUISITES
  • Basic understanding of C++ programming
  • Familiarity with function definitions and parameter passing in C++
  • Knowledge of standard input/output operations in C++
  • Experience with variable initialization and usage in C++
NEXT STEPS
  • Review C++ function parameter passing techniques
  • Learn about input validation in C++ to handle unexpected user input
  • Explore C++ string manipulation for enhanced output formatting
  • Study debugging techniques in C++ to troubleshoot common errors
USEFUL FOR

Beginner C++ programmers, educators teaching C++ basics, and anyone looking to understand user input handling in C++ applications.

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.
 
We have many threads on AI, which are mostly AI/LLM, e.g,. ChatGPT, Claude, etc. It is important to draw a distinction between AI/LLM and AI/ML/DL, where ML - Machine Learning and DL = Deep Learning. AI is a broad technology; the AI/ML/DL is being developed to handle large data sets, and even seemingly disparate datasets to rapidly evaluated the data and determine the quantitative relationships in order to understand what those relationships (about the variaboles) mean. At the Harvard &...

Similar threads

Replies
12
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 66 ·
3
Replies
66
Views
6K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
12K