![]() |
| ||
| Yes/No to 1/0 and if else statement I need to know how to have the user answer a question using yes or no and the program translating it into 1 or 0. I know this process involves a string... but anymore than that and I'm kinda lost. **Fixed second problem with the if else statement but still need help with the previous problem.** |
| ||
| Re: Yes/No to 1/0 and if else statement assuming answer is a string bool result; |
| ||
| Re: Yes/No to 1/0 and if else statement Thanks. I keep getting an error when I enter it. What would be the library for that? |
| ||
| Re: Yes/No to 1/0 and if else statement post code and error message(s) |
| ||
| Re: Yes/No to 1/0 and if else statement Well I actually figured that out but I do have another problem I could use some help with if you don't mind. The part that asks the credit rating, I need the user to be able to input good or bad. Then later on in the code the condition say if the credit rating is good it's approved. Know how to do that? #include <iostream> |
| ||
| Re: Yes/No to 1/0 and if else statement >>permanent_job == "yes" You can not compare character arrays like that -- only std::string. So you will have to call strcmp() to compare two character arrays if( strcmp(permanent_job,"yes") == 0) But if you change permanent_job to std::string then the comparison you made will work |
| ||
| Re: Yes/No to 1/0 and if else statement Hum... it works the way I have it... =S |
| ||
| Re: Yes/No to 1/0 and if else statement >>it works the way I have it... Depends on your definition of works. If you mean compiles, then the compiler is comparing addresses, not strings because the compiler isn't smart enough to know any different. Try running it and you will see that it doesn't do what you think its doing. Humm-- this is the output of your program -- no wonder we have a housing crises in this country! :) Quote:
Quote:
|
| ||
| Re: Yes/No to 1/0 and if else statement lmao okay i'll try to fix that... what about the good and bad thing though? |
| ||
| Re: Yes/No to 1/0 and if else statement do you mean you want to be able to enter "yes" or "no", or "good" and "bad" instead of 1 and 2? Just make it strings like all the others. You have other logic errors because no matter what I enter my application is always approved. Even after changing the character arrays to std::string. I think what you probably want is this: if(age >= 16 && credit_rating == 1 && house_owner == "yes" && permanent_job == "yes" && monthly_income > 3000) {You don't want to approve the loan unless all those conditions are met. |
| All times are GMT -4. The time now is 1:33 pm. |
Forum system based on vBulletin Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
©2003 - 2010 DaniWeb® LLC