Thread: getline statement

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    16

    getline statement

    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;
    }
    Last edited by Troll; 10-14-2005 at 07:56 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 05:19 AM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. getline help
    By ProjectsProject in forum C++ Programming
    Replies: 3
    Last Post: 06-14-2004, 11:12 AM
  4. getline with string class in Borland C++
    By johnnyd in forum C++ Programming
    Replies: 6
    Last Post: 03-08-2003, 02:59 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM