简单的IF语句 [英] Simple IF Statements
本文介绍了简单的IF语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好开发者. !!
我的代码无法按照我想要的方式工作,,,
为什么不执行COUT语句. . .
有什么建议. ??
Hello Developers. !!
My code isn''t working as the way i want, , ,
why the COUT statement is not executed. . .
Any Suggestions. ??
#include <iostream>
using namespace std;
int main ()
{
char isEmployer = 'E';
char hasLocation = 'L';
int hasAge = 0;
int hasSalary = 0;
cout << "enter details to get loan" << endl;
cout << "Employer?" << endl;
cin >> isEmployer;
cout << "Location?" << endl;
cin >> hasLocation;
cout << "Salary" << endl;
cin >> hasSalary;
if (isEmployer == 'E')
if (hasLocation=='L')
if(hasSalary > 50000)
cout << "You Are Allowed To Get The Loan" << endl;
else
cout << "Not Allowed To Get The Loan" << endl;
return 0;
}
推荐答案
if (isEmployer == 'E' && hasLocation=='L' && hasSalary > 50000)
cout << "You Are Allowed To Get The Loan" << endl;
我不在C ++中,但是逻辑编码错误.
如果isEmployer为E,则只有它会检查hasLocation,如果HasLocation为L,则只有它会检查HasSalary.现在,如果HasSalary为> 50000您将获得第一个字符串,否则将返回第二个字符串.但是对于除了前两个条件中的E或L之外的任何事情,仅在第三个条件中不会出现
应该是
I am not in C++, but the logic is coded wrongly.
Here if isEmployer is E then only it will check hasLocation, Then if HasLocation is L then only it will check HasSalary. Now if HasSalary is > 50000 you will get first string and else it will return second string. But for any thing other then E or L in first two condition it will not go in the third if only
It should have been
if (isEmployer == 'E')
{
if (hasLocation=='L')
if(hasSalary > 50000)
cout << "You Are Allowed To Get The Loan" << endl;
}
else
cout << "Not Allowed To Get The Loan" << endl;
或者您可以将逻辑AND
Or You can put logical AND
if (((isEmployer == 'E') && (hasLocation=='L') && (hasSalary > 50000))
cout << "You Are Allowed To Get The Loan" << endl;
else
cout << "Not Allowed To Get The Loan" << endl;
PS:我不确定C ++中逻辑AND条件的符号
谢谢
Milind
PS: I am not sure about symbol for logical AND condition in C++
Thanks
Milind
如果您真的不喜欢&&操作员尝试以下操作:
If you really dislike the && operator try this:
bool bOK = false;
if (isEmployer == 'E')
if (hasLocation == 'L')
if(hasSalary > 50000)
bOK = true;
if (bOK) cout << "OK..." << endl;
else cout << "Bad..." << endl;
希望对您有所帮助.
I hope this helps.
这篇关于简单的IF语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文