练习:if语句运用

 
#include <stdio.h>
int main(void)
{
 int tmp;
 printf("今天的天气是多少度?\n");
 scanf("%d",&tmp);
 if(tmp>16 ){
  printf("出行!\n");
 }
 return 0;
}
 
 
#include <stdio.h>
#include <string.h>
//练习:需购买一物品,价格1000元,有一下几个条件
//1、有体验卡可免费使用,0元;
//2、5折的折扣卷,500元;
//3、会员卡可优惠9折;900元;
int main(void)
{
 char answer[8]; //编写时需注意数组形式,否则会出问题
 printf("请问你有体验卡吗?[Yes|No]\n");
 scanf("%s",&answer);
 if (strcmp(answer,"yes") == 0){
  printf("这个物品你可以免费带回体验!\n");
  //printf加括号
  //scanf("%s",answer)
 }else if (printf("请问你有打5折的折扣卷吗?[yes|no]\n") && scanf("%s",answer) &&
  strcmp(answer,"yes") == 0){
  printf("这个物品打折后价格为500元。\n");
 }else if (printf("请问你有会员卡吗?可以打九折 [yes|no]\n") && scanf("%s",answer) &&
  strcmp(answer,"yes")== 0){
  printf("会员卡优惠后的价格为900元。\n");
 }
 return 0;
}
 
 

转载于:https://www.cnblogs.com/fzhiyaoy/p/10291554.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值