cin.getline problem

This is a discussion on cin.getline problem within the C++ Programming forums, part of the General Programming Boards category; When I run the program and tell for a new customer is couts the the "Please enter Name" but does ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    33

    cin.getline problem

    When I run the program and tell for a new customer is couts the the "Please enter Name" but does allow my to input anything. It also does this on the "Please enter phone number". Thanks for any help that i can get. I put the code tags hopes i did it right.
    Code:
    <code>
    #include <iostream.h>
    
    
    
    int main()
    {
    
    	char address[70];
    	char name[50];
    	char phone[20];
    	char description[200];
    	double total;
    	int zip;
    	int correct=2;
    	int id=0000;
    	int id2;
    	int option;
    	int quanf=1;
    	int quan46=1;
    	int qaun57=1;
    	int quan810=1;
    	int quanf57=1;
    	double pricef;
    	double price46;
    	double price57;
    	double price810;
    	double pricef57;
    	double product[10];
    	
    cout<<"Welcome to my first Register Program\n";
    cout<<"*******Good Luck Today*******\n";
    
    for (int i=0;i<100;i++)
    {
    cout<<"Please chose an option:\n";
    cout<<"(1)New Customer\n(2)Previos Customer\n(3)Exit\n";
    cin>>option;
    
    switch(option)
    {
    	case 1:
    		while(correct==2)
    		{
    			cout<<"Please enter name:\n";
    			cin.getline(name, 50, '\n');
    			
    			cout<<"Please enter address:\n";
    			cin.getline(address, 70, '\n');
    			
    			cout<<"Please enter zip code:\n";
    			cin>>zip;
    			
    			cout<<"Please enter phone number:\n";
    			cin.getline(phone, 20, '\n');
    			
    			cout<<"Please enter description:\n";
    			cin.getline(description, 200, '\n');
    			
    			cout<<endl<<"Name: "<<name<<endl;
    			cout<<"Address: "<<address<<endl;
    			cout<<"Zip Code: "<<zip<<endl;
    			cout<<"Phone: "<<phone<<endl;
    			cout<<"Description: "<<description<<endl;
    		
    		cout<<"Is this information correct?\n(1)Yes\n(2)No\n";
    		cin>>correct;
    		}
    		
    		product[0]=10.00;	//Product one: 4X6
    		product[1]=10.00;	//Product two: Frame
    		product[2]=15.00;	//Product three: 5X7
    		product[3]=15.00;	//Product four: Frame with 5X7
    		product[4]=20.00;	//Product five: 8X10
    		product[5]=0.00;	//Product six: Other
    		
    		correct=2;
    		while(correct==2)
    		{
    			cout<<"How many 4X6 were purchase:\n";
    			cin>>quan46;
    			
    			cout<<"How many 5X7 were purchase:\n";
    			cin>>qaun57;
    			
    			cout<<"How many 8X10 were purchase:\n";
    			cin>>quan810;
    			
    			cout<<"How many FRAMES were purchase:\n";
    			cin>>quanf;
    			
    			cout<<"How many FRAMES W/ 5X7 were purchase:\n";
    			cin>>quanf57;
    			
    			cout<<"4X6: "<<quan46<<endl;
    			cout<<"5X7: "<<qaun57<<endl;
    			cout<<"8X10: "<<quan810<<endl;
    			cout<<"Frame(s): "<<quanf<<endl;
    			cout<<"Frames w/ 5X7: "<<quanf57<<endl;
    			
    			cout<<"Is this Correct?\n(1)Yes\n(2)No\n";
    			cin>>correct;	
    		}
    		
    		price46=quan46*product[0];
    		price57=qaun57*product[2];
    		price810=quan810*product[4];
    		pricef=quanf*product[1];
    		pricef57=quanf57*product[3];
    		
    		total=price46+price57+price810+pricef+pricef57;
    		
    		cout<<"\nTotal Cost: "<<total<<endl;
    		
    
    		break;	
    			
    	case 2:
    			cout<<"Please enter there ID number\n";
    			cin>>id2;
    			//Will then search for the id number in the output file.
    		break;
    
    	case 3:
    			cout<<"This is just a test case 3\n";
    		break;
    		
    	default:
    		cout<<"Your entered an Invalid choice\n";
    };
    
    cout<<"Hopefully it works\n";
    break;
    }
    
    
     return 0;
    }
    </code>

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    This is as good an explanation as I've seen.

    http://www.augustcouncil.com/~tgibs...ial/iotips.html

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    The link you listed doesn't seem to work.

    You would think they would explain this problem in beginning C++ texts, but they don't. Try clicking on number 4 here for an explanation:

    http://www.augustcouncil.com/~tgibso...al/iotips.html
    Last edited by 7stud; 04-18-2003 at 04:26 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM
  3. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  4. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 09:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21