嘿,我需要帮助编写一个简单的程序。我希望能够演示整数的使用以及使用模数的余数。我陷入了如何计算信息的困境。任何帮助将不胜感激,但这是总体思路。该计划包括以下内容:
1 week = 40 hours ($200 per week) 1 day = 7 hours ($45 per day) ($2 per hour)
Sample run:
Enter the total hours:59 (59 is just an example.) You have: 1week 2day(s) 5hr(s) Payment: $300.00
Here's what I've come up with so far...
int main(){
int totalWeekHrs = 0,
totalDayHrs = 0,
totalWorkedHrs = 0;
float totalPayment = 0,
payPerWeek = 0,
payPerDay = 0,
PayPerHr = 0;
// Input process
printf("Enter the total hours :");
scanf("%i",&totalWeekHrs,&totalDayHrs,&totalWorkedHrs);
// Calculative process
system("pause");
}
最佳答案
这听起来像家庭作业,所以我将解释模数的工作原理。
模运算符 % 执行整数除法并返回余数。例如:
int foo = 6;
int bar = 4;
int remainder = foo % bar;
在该示例中,余数
将设置为 2。
您可以阅读有关模运算符 here 的更多信息。 .
关于c - 基本 C 编程帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6063003/