brisk172 brisk172 - 1 year ago 130
C++ Question

C++ Function Coding

I just started learning functions. I'm trying to write this code with using a function to have a user input the names. I can't figure out what the argument should be. I thought I could put in getName( passing an array into it, but I'm doing it wrong. What should the correct parameter be?

void getName(Horse &); //function prototype
struct Horse
string name;
array<Horse, horseCount> Horses;
for (Horse &i : Horses)
void getName(Horse &Nag)
cout << "Enter a horse's name: ";

Answer Source

You are passing a std::string to getName() when it actually expects Horse&.

You must call it as getname(i) to actually pass the Horse object.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download