当前位置: 首页 > news >正文

没建网站 备案建筑设计集团

没建网站 备案,建筑设计集团,文具网站建设策划书,建立无上气运皇朝C中的运算符总结&#xff08;4&#xff09;&#xff1a;逻辑运算符&#xff08;下&#xff09; 以下程序演示了如何使用条件语句和逻辑运算符根据变量的值执行不同的代码行&#xff1a; #include <iostream> using namespace std;int main() {cout << "Use …

C++中的运算符总结(4):逻辑运算符(下)

以下程序演示了如何使用条件语句和逻辑运算符根据变量的值执行不同的代码行:

#include <iostream>
using namespace std;int main()
{cout << "Use boolean values(0 / 1) to answer the questions" << endl;cout << "Is it raining? ";bool isRaining = false;cin >> isRaining;cout << "Do you have buses on the streets? ";bool busesPly = false;cin >> busesPly;// Conditional statement uses logical AND and NOTif (isRaining && !busesPly)cout << "You cannot go to work" << endl;elsecout << "You can go to work" << endl;if (isRaining && busesPly)cout << "Take an umbrella" << endl;if ((!isRaining) && busesPly)cout << "Enjoy the sun and have a nice day" << endl;return 0;
}

输出:

Use boolean values(0 / 1) to answer the questions
Is it raining? 1
Do you have buses on the streets? 1
You can go to work
Take an umbrella

再次运行的输出:

Use boolean values(0 / 1) to answer the questions
Is it raining? 1
Do you have buses on the streets? 0
You cannot go to work

最后一次运行的输出:

Use boolean values(0 / 1) to answer the questions
Is it raining? 0
Do you have buses on the streets? 1
You can go to work
Enjoy the sun and have a nice day

第 15 行包含条件表达式 (isRaining && !busesPly),可将其读作 “下雨且没有公交车”。这个表达式使用了逻辑 AND 运算符将没有公交车(对有公交车执行逻辑 NOT 运算)和下雨关联起来。

以下程序演示了如何将逻辑运算符 NOT 和 OR( ! 和 ||)用于条件处理。

#include <iostream>
using namespace std;int main()
{cout << "Answer questions with 0 or 1" << endl;cout << "Is there a discount on your favorite car? ";bool onDiscount = false;cin >> onDiscount;cout << "Did you get a fantastic bonus? ";bool fantasticBonus = false;cin >> fantasticBonus;if (onDiscount || fantasticBonus)cout << "Congratulations, you can buy that car!" << endl;elsecout << "Sorry, waiting a while is a good idea" << endl;if (!onDiscount)cout << "Car not on discount" << endl;return 0;
}

输出:

Answer questions with 0 or 1
Is there a discount on your favorite car? 0
Did you get a fantastic bonus? 1
Congratulations, you can buy that car!
Car not on discount

再次运行的输出:

Answer questions with 0 or 1
Is there a discount on your favorite car? 0
Did you get a fantastic bonus? 0
Sorry, waiting a while is a good idea
Car not on discount

最后一次运行的输出:

Answer questions with 0 or 1
Is there a discount on your favorite car? 1
Did you get a fantastic bonus? 1
Congratulations, you can buy that car!  

分析:

这个程序建议您能够打折或得到很高的补贴时就把车买了,不然就再观望观望。它还在第 19 行使用了逻辑非运算来提醒您不打折。第 14 行使用了一条 if 语句,而第 16 行是与之配套的 else 语句。在条件 (onDiscount || fantasticBonus) 为 true 时,将执行第 15 行的语句。这个表达式包含逻辑运算符||,仅当您喜欢的汽车打折或能够获得很高的补贴时, 该表达式才为 true。当该表达式为 false 时, 将执行 else语句后面的语句(第 17 行)。

该文章会更新,欢迎大家批评指正。

推荐一个零声学院免费公开课程,个人觉得老师讲得不错,
分享给大家:Linux,Nginx,ZeroMQ,MySQL,Redis,
fastdfs,MongoDB,ZK,流媒体,CDN,P2P,K8S,Docker,
TCP/IP,协程,DPDK等技术内容,点击立即学习:
服务器课程:C++服务器

学习链接

http://www.yayakq.cn/news/714639/

相关文章:

  • 莆田做网站的公司如何升级网站后台
  • 郑州七彩网站建设公司怎么样简述商务网站建设步骤
  • 互联网公司裁员应聘网站优化的简历怎么做
  • 网站内移动的图片怎么做的百度推广怎么优化关键词的质量
  • 制作企业网站与app有什么不同网站 关键词 怎么改
  • 为企网站南城网站建设公司策划
  • 做今网站电商网站成品案例
  • 厦门网站优化公司关于新品牌的营销策划
  • 网站建设 牛商网平面设计类网站
  • 惠州网站建设制作公司中山市网站建设
  • 网站域名以co与com有什么不同做网站负责人有法律风险吗
  • 大连坐网站公司网站报价
  • 网站建设佰金手指科杰二六10号店分销平台
  • ps做的网站图片好大浙江省网站集约化建设通知
  • 网站备案 价格线上营销推广的公司
  • 网站建设答辩内容外贸和网站制作
  • 最常见企业网站有哪些网站搭建 保定
  • 网站关键词多少个合适做利基网站用备案
  • 国内外网站开发技术网站开发项目意义
  • 动漫网站开发与建设网上商城采购流程
  • 网站网域名查询南平购物网站开发设计
  • 模板网站制作视频报告文学
  • 帮别的公司做网站违法吗百度手机助手网页
  • 找工作哪个网站好招聘信息如何在免费网站上做推扩
  • 化妆品网站建设策划书百度网址怎么写
  • 创可贴网页设计网站专业免费网站建设
  • iis7.5 添加网站.tel域名不可以做网站域名吗?
  • 盖州网站建设wordpress插件vpn
  • 网站建设中企动力最佳a5类似58同城的网站怎么做
  • 做餐饮网站的目的与意义外国网站快速申请qq