944,092 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 477
  • C++ RSS
Oct 3rd, 2009
-1

nested if, else

Expand Post »
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;
}
Similar Threads
Reputation Points: 9
Solved Threads: 0
Newbie Poster
sebassn is offline Offline
22 posts
since Oct 2009
Oct 3rd, 2009
0

Re: nested if, else

Why don't you write that for getting input from the user:

string breed;
cin >> breed;

This method does not get the "\n".
Reputation Points: 72
Solved Threads: 26
Posting Whiz in Training
GDICommander is offline Offline
209 posts
since Jun 2008
Oct 3rd, 2009
0

Re: nested if, else

Yes, be consistent with your input. Always use getline() and you shouldn't have to worry about cin.ignore()
Moderator
Reputation Points: 3281
Solved Threads: 895
Posting Sage
WaltP is offline Offline
7,747 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: How to find largest/smallest position in a vector?
Next Thread in C++ Forum Timeline: File handling/database management





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC