我的数学在TextView上被打破了

时间:2017-01-29 17:46:51

标签: java android

说实话,我刚刚开始编程,但对于我的生活,我无法弄清楚我错在哪里。

数学是: 10美元/ 2小时

每小时的提示= 5(我得到0.2)

服务员1付= 10(我得0.4?)

screenshot

MainActivity中的计算:

// HTTP
define('HTTP_SERVER', 'https://example.com/admin/');
define('HTTP_CATALOG', 'https://example.com/');

// HTTPS
define('HTTPS_SERVER', 'https://example.com/admin/');
define('HTTPS_CATALOG', 'https://example.com/');

将结果转换为TextViews:

double resultTotalHours = cWaiter1Hours + cWaiter2Hours + cWaiter3Hours + cWaiter4Hours;
            double calcTipsPerHour = resultTotalHours / totalTips;
            double resultBarsCut = (totalTips * (cBarCutInput / 100));
            double resultTaxDeposit = resultTotalHours * 3;
            double resultTipsPerHour = (totalTips - resultBarsCut - resultTaxDeposit) / resultTotalHours;

            double resultWaiter1Pay = cWaiter1Hours * resultTipsPerHour;
            double resultWaiter2Pay = cWaiter2Hours * resultTipsPerHour;
            double resultWaiter3Pay = cWaiter3Hours * resultTipsPerHour;
            double resultWaiter4Pay = cWaiter4Hours * resultTipsPerHour;

            double resultWaiter1NoTax = cWaiter1Hours * calcTipsPerHour;
            double resultWaiter2NoTax = cWaiter2Hours * calcTipsPerHour;
            double resultWaiter3NoTax = cWaiter3Hours * calcTipsPerHour;
            double resultWaiter4NoTax = cWaiter4Hours * calcTipsPerHour;

2 个答案:

答案 0 :(得分:0)

问题在于:

double calcTipsPerHour = resultTotalHours / totalTips;

目前正在做2/10 = 0.2。

你想做倒数:

double calcTipsPerHour = totalTips / resultTotalHours;

这也应该可以解决服务员的工资

答案 1 :(得分:0)

你在分子和分母中放了几个小时,这样你得到了你想要的反转:小时/小费

你想要的是:

#include<stdio.h>
int main() {
 int n;
 scanf("%d", &n);
 int arr[n];
 for(int c=0; c<=n;c++){
   arr[c]=0;
 }
 for(int c=0; c<=n;c++){
   printf("%d\n", arr[c]);
 }
}