nested if, else

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 22
Reputation: sebassn is an unknown quantity at this point 
Solved Threads: 0
sebassn sebassn is offline Offline
Newbie Poster

nested if, else

 
-1
  #1
Oct 3rd, 2009
When I run the code, it works till the part where it asks about the dog's bredd, I press enter and it asks me about the dog's name, that's not supposed to appear. And also, when I enter the weight and press enter nothing happen, it's supposed to give me an answer but I don't know what's going on!, help me please!
thanks



cout<<"First Name and Last Name: "<<endl;
getline(cin,naME);


cout<<"Do you own a dog at the present time? Type 1 for YES or 0 for NO: "<<endl;
cin>>gotDog;

if(gotDog){
cout<<"What is the dog's breed?: "<<endl;
cin.ignore(200, '\n');
getline(cin,brEEd);

if(brEEd == "pit-bull"){
cout<<"You are not welcome to the condominium!"<<endl;
cout<<"It's illegal to have a pit-bull in South Florida."<<endl;

}else{
cout<<"How much does it weight?: "<<endl;
cin.ignore(200, '\n');
getline(cin,lbs);
}

if(lbs >= "30"){
cout<<"You are not welcome to the condominium!"<<endl;
cout<<"It's prohibited to have dogs that weights more then 30 lbs."<<endl;
}else{
cout<<"What is the dog's name? "<<endl;
cin.ignore(200, '\n');
getline(cin,dogNm);
}
}else{
cout<<"You are welcome to the condominium!"<<endl;
}
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 147
Reputation: GDICommander is an unknown quantity at this point 
Solved Threads: 19
GDICommander's Avatar
GDICommander GDICommander is offline Offline
Junior Poster

Re: nested if, else

 
0
  #2
Oct 3rd, 2009
Why don't you write that for getting input from the user:

string breed;
cin >> breed;

This method does not get the "\n".
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: nested if, else

 
0
  #3
Oct 3rd, 2009
Yes, be consistent with your input. Always use getline() and you shouldn't have to worry about cin.ignore()
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC