Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 1881|回复: 7
打印 上一主题 下一主题

紧急!!! 快帮帮忙 C++ 的问题!!!

[复制链接]

15

主题

0

好友

46

积分

初级会员

Rank: 1

跳转到指定楼层
1#
发表于 2011-6-18 07:08 PM |只看该作者 |倒序浏览
本帖最后由 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");
}




收藏收藏0

790

主题

251

好友

3万

积分

至尊元首

哥就是浮云,别跟随哥呀

Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18

雪隆 & 槟城 - 最佳资源分享比赛

2#
发表于 2011-6-18 08:29 PM |只看该作者
这个好像是TARC DIA1 PCD 的assignment
programming这东西...有时google都没答案的
问你的coursemate吧


回复

使用道具 举报

8

主题

3

好友

6357

积分

百变名嘴

Rank: 13Rank: 13Rank: 13Rank: 13

3#
发表于 2011-6-18 11:56 PM |只看该作者




回复

使用道具 举报

8

主题

3

好友

6357

积分

百变名嘴

Rank: 13Rank: 13Rank: 13Rank: 13

4#
发表于 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");
}


回复

使用道具 举报

8

主题

3

好友

6357

积分

百变名嘴

Rank: 13Rank: 13Rank: 13Rank: 13

5#
发表于 2011-6-19 12:01 AM |只看该作者
不好意思,我才第一年学这些,不知道你的要求,所以就只有这样~
不知道是不是你要的。。

ps:这些是C language 不是 C++~


回复

使用道具 举报

15

主题

0

好友

118

积分

高级会员

Rank: 3Rank: 3Rank: 3

6#
发表于 2011-7-12 07:45 AM |只看该作者
C的代码大部分不用改写可以直接在C++上运行


回复

使用道具 举报

57

主题

1

好友

3274

积分

本站名嘴

Rank: 11Rank: 11

7#
发表于 2011-7-12 11:43 PM |只看该作者
这是C吧   C++ 不是printf 是用 cout 的


回复

使用道具 举报

46

主题

6

好友

6456

积分

百变名嘴

Rank: 13Rank: 13Rank: 13Rank: 13

8#
发表于 2011-7-13 11:23 PM |只看该作者
不错。 超级无敌难的功课。
给billgate 都做不出


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-10-25 10:35 AM , Processed in 0.114449 second(s), 28 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部