In the function at the bottom, I need a getline statement to accomodate the cin statement so that we can enter a string of text with spaces in it for "hole_type". I ran the program and after entering any string for an answer, the program skips the rest of the inputs and prints out the rest of the program.
What can you do for me?
Code:
#include<iostream.h>
#include<cstring.h>
#include<conio.h>
using namespace std;
struct GolfHole
{
char hole_type[20];
int yardage,
par,
hole_number;
GolfHole(char hole_type[20] = "dog-leg right")
{
hole_type = "dog-leg right";
yardage = 254;
par = 4;
hole_number = 1;
}
};
GolfHole get_golf_hole_info();
void main()
{
GolfHole HoleA;
HoleA = get_golf_hole_info();
cout<<"\n\nThe hole number is:"<<HoleA.hole_number<<".\n";
cout<<"\n\nThe hole-type is:"<<HoleA.hole_type<<".\n";
cout<<"\n\nThe hole is "<<HoleA.yardage<<" yards long.\n";
cout<<"\n\nThe par for this hole is:"<<HoleA.par<<".\n";
GolfHole HoleB;
HoleB = get_golf_hole_info();
cout<<"\n\nThe hole number is:"<<HoleB.hole_number<<".\n";
cout<<"\n\nThe hole-type is:"<<HoleB.hole_type<<".\n";
cout<<"\n\nThe hole is "<<HoleB.yardage<<" yards long.\n";
cout<<"\n\nThe par for this hole is:"<<HoleB.par<<".\n";
getch();
}
GolfHole get_golf_hole_info()
{
GolfHole info;
cout<<"\nWhat is the number of this hole?: ";
cin>> info.hole_number;
cout<<"\nDescribe the type of hole you'd like: ";
cin.getline(info.hole_type, 20); //<-right here.
cout<<"\nHow long is the hole in yards?: ";
cin>> info.yardage;
cout<<"\nWhat is the par for this hole?: ";
cin>>info.par;
return info;
}