本节书摘来自异步社区《C语言编程初学者指南》一书中的第2章,第2.10节,作者【美】Keith Davenport(达文波特) , M1ichael Vine(维恩),更多章节内容可以访问云栖社区“异步社区”公众号查看
2.10 本章程序:Shop Profit
本章的一个简单的程序,是完成一家销售游戏装备的商店的一部分计算工作。Shop Profit程序用到了本章中的很多概念,例如,变量、使用printf()函数和scanf()函数进行输入和输出,以及算术运算基础,如图2.4所示。
编写Shop Profit程序所需的所有C代码如下所示:
include <stdio.h>
int main()
{
float fRevenue, fCost;
/* profit = revenue – cost */
printf("\nEnter total revenue: ");
scanf("%f", &fRevenue);
printf("\nEnter total cost: ");
scanf("%f", &fCost);
printf("\nYour profit is $%.2f\n", fRevenue – fCost);
return 0;
}
图2.4 使用Shop Profit程序展示本章中的概念