1. 程式人生 > >練習:if語句運用

練習:if語句運用

ans src include std .com png oid ring 免費使用

#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;
} 技術分享圖片
技術分享圖片

練習:if語句運用