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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top