The GetInt(string) function of Exercise 4.3 is designed to be generic function w
ID: 3529231 • Letter: T
Question
The GetInt(string) function of Exercise 4.3 is designed to be generic function which can be used anytime we need to display a prompt and read an integer from the keyboard. For example, suppose we also wish to read a person's height in addition to reading their age. We could write the code two ways: (1) write two functions, GetAge() and GetHeight(), which essentially do the same thing; and then call GetAge() and GetHeight() from main(); or (2) write one function, GetInt(string) as described above; and then call GetInt(string) twice from main()Explanation / Answer
#include#includeusing namespace std; int GetInt(string prompt){ int n; coutn; return n; } int main(){ int age=GetInt("Enter your age?"); int height=GetInt("Enter your height(cm)?"); coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.