运行结果:
C语言代码:
/* c how to program 习题 3.18 */
#include <stdio.h>
#include <stdlib.h>
int main()
{
//定义变量
double sales, salary, baseSalary = 200, royalty = 0.09;
//请输入第一个职工销售额
printf("Enter sales in dollars (-1 to end): ");
scanf("%lf", &sales);
while(sales != -1.0){
//计算工资
salary = baseSalary + sales * royalty;
//打印工资
printf("Salary is: $%.2lf\n\n", salary);
//请输入下一个职工销售额
printf("Enter sales in dollars (-1 to end): ");
scanf("%lf", &sales);
}
return 0;
}