gpt4 book ai didi

C、薪资提成

转载 作者:行者123 更新时间:2023-11-30 21:39:11 24 4
gpt4 key购买 nike

是的,这是作业:

One chemical company pays its sales people on a commission basis. The sales people receive $200/ week plus 9% of their gross sales for that week. For example, a sales person who sells $5,000.00 worth of chemicals will receive $200 plus the 9% of $5,000 for a total of $650.

Develop a program that will input a sales person gross sales an will calculate and display that person's earnings.

Example of an output:

Salary is : $650.00

Be sure that in your program you consider the following:

Your program includes:

  1. proper case, variable names(meaningful and use conventions)

  2. proper organization, indentation, white space, and comments

  3. Has the right inputs and outputs, computes correct results, is efficient

我的作品;

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main() {

const double commission = 0.09;
double gross_sales, salary;

printf("Enter amount of gross sales\n");
scanf("%.03d", &gross_sales);

printf("Your salary for this week: %.03d\n", &salary);
scanf("salary = gross_sales*commission + 200 %.03d", &salary);

system("pause");
}

我不确定我需要做什么 - 你能帮忙吗?

最佳答案

scanf("%.03d", &gross_sales); // gross_sales is double

d 说明符用于整数。对于 double

应该是 lf

要打印变量的内容,您不需要为地址运算符添加前缀,因此

printf("Your salary for this week: %.03d\n", &salary);

错了,但应该是

printf("Your salary for this week: %.03lf\n", salary);

但是,您现在可能已经意识到此时无需打印工资,因为您还没有读取该变量。事实上,标准(6.7.9->10)说:

If an object that has automatic storage duration is not initialized explicitly, its value is indeterminate

最后的

scanf 需要与第一点中提到的相同修改。

关于C、薪资提成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38342460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com