JBTALKS.CC
标题:
紧急!!! 快帮帮忙 C++ 的问题!!!
[打印本页]
作者:
eric1993
时间:
2011-6-18 07:08 PM
标题:
紧急!!! 快帮帮忙 C++ 的问题!!!
本帖最后由 eric1993 于 2011-6-18 07:10 PM 编辑
各位大大帮帮忙吧!!!!!
小弟正面对个大问题!!!
要怎样用 ceil() & floor() function 和 mathematic 的方式来form个formula
[1,2,3,4] = 0
[6,7,8,9] = 5
[5] = 5
用 % 的方式小弟想到头都快穿了!!!! 救命啊!
以下是小弟的 source code
#include <stdio.h>
#include <math.h>
#define GOV_TAX 0.06
#define SER_TAX 0.10
void main ()
{
int num1;
char des1[20];
double unitPrice, sum, sumtotal, gov_tax, ser_tax, discVouc, padis, lastVal, chardue, ceil_padis;
float cash;
printf("Enter Description > ");
scanf("%s", &des1);
printf("Enter Quantities > ");
scanf("%d", &num1);
printf("Enter Prices Of Descriptions > ");
scanf("%lf", &unitPrice);
printf("Enter amount of Discount Voucher > ");
fflush(stdin);
scanf("%lf", &discVouc);
printf("Enter a customer cash : ");
fflush(stdin);
scanf("%f",&cash);
sum = num1 * unitPrice;
gov_tax = sum * GOV_TAX;
ser_tax = sum * SER_TAX;
sumtotal = sum + gov_tax + ser_tax;
padis = sumtotal - discVouc;
ceil_padis = ceil(padis * 10) / 10;
<< 我的formula 不够完整,
lastVal = ceil_padis;
chardue = cash - lastVal;
printf("\n");
printf(" G-Core Software Development \n");
printf("\n");
printf(" Welcome to KLFC Sales Receipt System \n ");
printf("\n");
printf("\n");
printf(" RECEIPT \n");
printf("+-------------+----------+-------------+------------------+\n");
printf("| Description | Quantity | Unit Prices | Total Amount(RM) |\n");
printf("+-------------+----------+-------------+------------------+\n");
printf("| %7.13s | %d | %8.2f | %8.2f |\n", des1, num1 , unitPrice, sum);
printf("+------------------------+-------------+------------------+\n");
printf("| | Sub Total | %8.2f |\n", sum);
printf("| Goverment Tax 6%% | | %8.2f |\n", gov_tax);
printf("| Service Tax 10%% | | %8.2f |\n", ser_tax);
printf("| | +------------------+\n");
printf("| | Grand Total | %8.2f |\n", sumtotal);
printf("+========================+=============+==================+\n");
printf("| Grand Total %8.2f |\n", sumtotal);
printf("| Discount Amount %8.2f |\n", discVouc);
printf("| -------------- |\n");
printf("| Payable Amount %8.2f |\n", padis);
printf("| ============== |\n");
printf("| Adjusted Amount %8.2f|\n", lastVal); << 这边啊!
printf("+=========================================================+\n");
printf(" Total %8.2f \n", lastVal);
printf(" Cash %8.2f \n", cash);
printf(" Change Due %8.2f \n", chardue);
printf("+=========================================================+\n");
printf(" THANKYOU AND HAVE A NICE DAY \n");
printf("\n");
}
作者:
uncopyrightable
时间:
2011-6-18 08:29 PM
这个好像是TARC DIA1 PCD 的assignment
programming这东西...有时google都没答案的
问你的coursemate吧
作者:
LoveQueenie
时间:
2011-6-18 11:56 PM
作者:
LoveQueenie
时间:
2011-6-18 11:58 PM
SOURCE CODE
#include <stdio.h>
#include <math.h>
#define GOV_TAX 0.06
#define SER_TAX 0.10
void main ()
{
int num1;
char des1[20];
double unitPrice, sum, sumtotal, gov_tax, ser_tax, discVouc, padis, lastVal, chardue, ceil_padis;
float cash;
printf("Enter Description > ");
scanf("%s", &des1);
printf("Enter Quantities > ");
scanf("%d", &num1);
printf("Enter Prices Of Descriptions > ");
scanf("%lf", &unitPrice);
printf("Enter amount of Discount Voucher > ");
fflush(stdin);
scanf("%lf", &discVouc);
printf("Enter a customer cash : ");
fflush(stdin);
scanf("%f", &cash);
sum = num1 * unitPrice;
gov_tax = sum * GOV_TAX;
ser_tax = sum * SER_TAX;
sumtotal = sum + gov_tax + ser_tax;
padis = sumtotal - discVouc;
int ceOfl=int(padis*100);
if(ceOfl%10<4){
ceil_padis = floor(padis * 10) / 10;
}else if(ceOfl%10>5){
ceil_padis = ceil(padis * 10) / 10; //<< 我的formula 不够完整,
}else{
ceil_padis = padis;
}
lastVal = ceil_padis;
chardue = cash - lastVal;
printf("\n");
printf(" G-Core Software Development \n");
printf("\n");
printf(" Welcome to KLFC Sales Receipt System \n ");
printf("\n");
printf("\n");
printf(" RECEIPT \n");
printf("+-------------+----------+-------------+------------------+\n");
printf("| Description | Quantity | Unit Prices | Total Amount(RM) |\n");
printf("+-------------+----------+-------------+------------------+\n");
printf("| %7.13s | %d | %8.2f | %8.2f |\n", des1, num1 , unitPrice, sum);
printf("+------------------------+-------------+------------------+\n");
printf("| | Sub Total | %8.2f |\n", sum);
printf("| Goverment Tax 6%% | | %8.2f |\n", gov_tax);
printf("| Service Tax 10%% | | %8.2f |\n", ser_tax);
printf("| | +------------------+\n");
printf("| | Grand Total | %8.2f |\n", sumtotal);
printf("+========================+=============+==================+\n");
printf("| Grand Total %8.2f |\n", sumtotal);
printf("| Discount Amount %8.2f |\n", discVouc);
printf("| -------------- |\n");
printf("| Payable Amount %8.2f |\n", padis);
printf("| ============== |\n");
printf("| Adjusted Amount %8.2f|\n", lastVal); // << 这边啊!
printf("+=========================================================+\n");
printf(" Total %8.2f \n", lastVal);
printf(" Cash %8.2f \n", cash);
printf(" Change Due %8.2f \n", chardue);
printf("+=========================================================+\n");
printf(" THANKYOU AND HAVE A NICE DAY \n");
printf("\n");
}
作者:
LoveQueenie
时间:
2011-6-19 12:01 AM
不好意思,我才第一年学这些,不知道你的要求,所以就只有这样~
不知道是不是你要的。。
ps:这些是C language 不是 C++~
作者:
no7z
时间:
2011-7-12 07:45 AM
C的代码大部分不用改写可以直接在C++上运行
作者:
qwqwqwqw
时间:
2011-7-12 11:43 PM
这是C吧 C++ 不是printf 是用 cout 的
作者:
宅男-兜着走
时间:
2011-7-13 11:23 PM
不错。 超级无敌难的功课。
给billgate 都做不出
欢迎光临 JBTALKS.CC (https://jbtalks.my/)
Powered by Discuz! X2.5