使用赋值运算符计算含税金额的 C 程序
问题
用 C 编写一个程序,让用户输入金额(单位为美元),然后显示加上 18% 税之后的金额。
解决方案
让我们考虑餐厅工作人员在顾客的每一张账单上加 18% 的税。
用于计算税的逻辑是 −
value=(money + (money * 0.18));
应将金额乘以 18%,并将其添加到金额中,然后餐厅工作人员才能从顾客那里收取带税的金额。
示例
#include<stdio.h>
int main(){
float money,value;
printf("enter the money with dollar symbol:");
scanf("%f",&money);
value=(money + (money * 0.18));
printf("amount after adding tax= %f
",value);
return 0;
}输出
enter the money with dollar symbol:250$ amount after adding tax= 295.000000
示例
让我们考虑更改百分比的同一程序 −
#include<stdio.h>
int main(){
float money,value;
printf("enter the money with dollar symbol:");
scanf("%f",&money);
value=(money + (money * 0.20));
printf("amount after adding tax= %f
",value);
return 0;
}输出
enter the money with dollar symbol:250$ amount after adding tax= 300.000000
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP