JBTALKS.CC

标题: 【入门C作业】【strcmp / for / while】 #25楼 有Debug Coding提供。 [打印本页]

作者: 无我不在    时间: 2009-1-10 11:23 PM
标题: 【入门C作业】【strcmp / for / while】 #25楼 有Debug Coding提供。
这PROGRAM是一篇帮顾客计算所需清还的税务。
Program会要求一些个人资料,如IC、名字、生日等等。最后要求Total income, total relief, 和total rebate。

软件功用:
可以不断输入很多户口,然后储存起来。
之后,利用IC搜索资料和显示税务。

税务的算法是正确的。

Coding样本在#25-27楼!由衷感谢Super-Tomato帮忙。


各位高手,我还有一些想请教你们。见#27楼。


[ 本帖最后由 无我不在 于 2009-1-23 11:05 PM 编辑 ]
作者: Super-Tomato    时间: 2009-1-11 12:00 AM
原帖由 无我不在 于 2009-1-10 11:23 PM 发表
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
    int code=37, i=-1;
    char choice=0, icno_search[8];
    char name[10][50]={""}, icno[10][8]={""}, DOB[10][10]={""}, sex[10]={""};
    float total_income[10]={0}, total_relief[10]={0}, total_rebate[10]={0}, pre_payment[10]={0}, taxable_amount[10]={0};
    float amount_payment[10]={0};
   
    while(choice!='D'&& choice!='d')
    {
        printf("Tax Advisor Program\n");
        printf("(A)\tDisplay taxation rate\n");
        printf("(B)\tInput tax payer's particulars\n");
        printf("(C)\tCompute and display tax payable\n");
        printf("(D)\tQuit\n");
        printf("Enter Choice:  ");
        flushall();
        scanf("%c", &choice);

        switch(choice)
        {
            case 'a'    :
            case 'A'    : printf("\n\nTax Rate Information Table\n");
                          printf("==========================");
                          printf("\n\t\tIncome\t\tRate\n");
                          printf("\t\t$\t\t(%c)\n", code);
                          printf("On the frist\t20,000\t\t0\n");
                          printf("On the next\t10,000\t\t3.5\n");
                          printf("On the next\t10,000\t\t5.5\n");
                          printf("On the next\t40,000\t\t8.5\n");
                          printf("On the next\t80,000\t\t14\n");
                          printf("On the next\t160,000\t\t17\n");
                          printf("Above\t\t320,000\t\t20\n");
                          printf("\n\n");
                          break;

            case 'b'    :
            case 'B'    : i = i + 1;
                          printf("\n\n");
                          printf("Fill Your Descriptions in the following\n");
                          printf("=======================================");
                          printf("\nEnter NRIC no.: ");
                          flushall();
                          scanf("%s", &icno);
                          printf("Enter Name: ");
                          flushall();
                          gets(name);
                          printf("Enter Date of Birth(DD-MM-YYYY): ");
                          flushall();
                          gets(DOB);
                          printf("Enter Sex(M/F): ");
                          flushall();
                          scanf("%c", &sex);
                          printf("Enter Total Income: $");
                          flushall();
                          scanf("%f", &total_income);
                          printf("Enter Total Relief: $");
                          flushall();
                          scanf("%f", &total_relief);
                          printf("Enter Total Rebate: $");
                          flushall();
                          scanf("%f", &total_rebate);
                          printf("\n");

                          printf("**To compute and display your amount payment, please press C to continue.\n\n\n");
                                             
                          pre_payment = total_income - total_relief;

                          if(pre_payment>=0 && pre_payment<20000)
                          {
                              taxable_amount = pre_payment * 0;
                          }
                          else
                          {
                              if(pre_payment > 20000 && pre_payment <= 30000)
                              {
                                  taxable_amount = 0 + (pre_payment-20000) * 0.035;
                              }
                              else
                              {
                                  if(pre_payment > 30000 && pre_payment <= 40000)
                                  {
                                      taxable_amount = 350 + (pre_payment-30000) * 0.055;
                                  }
                                  else
                                  {
                                      if(pre_payment > 40000 && pre_payment <= 80000)
                                      {
                                          taxable_amount = 900 + (pre_payment-40000) * 0.085;
                                      }
                                      else
                                      {
                                          if(pre_payment > 80000 && pre_payment <= 160000)
                                          {
                                              taxable_amount = 4300 + (pre_payment-80000) * 0.14;
                                          }
                                          else
                                          {
                                              if(pre_payment > 160000 && pre_payment <= 320000)
                                              {
                                                  taxable_amount = 15500 + (pre_payment-160000) * 0.17;
                                              }
                                              else
                                              {
                                                  taxable_amount = 42700 + (pre_payment-320000) * 0.2;
                                              }
                                          }
                                      }
                                  }
                              }
                          }
                          amount_payment = taxable_amount - total_rebate;
                          break;

            case 'c'    :
            case 'C'    : i = i + 1;
                          printf("Enter Your NRIC: ");
                          flushall();
                          gets(icno_search);                                                      
                           
                            if(strcmp(icno, icno_search) == 0)
                            {
                                printf("\n\nYour Total Amount Payment");
                                printf("\n=========================");
                                printf("\nNRIC\t\t\t   : %s", icno);
                                printf("\nName\t\t\t   : %s", name);
                                printf("\nDate of Brith\t\t   : %s\n", DOB);
                                printf("Sex\t\t\t   : %c\n\n", sex);
                                printf("Total income\t\t   :  $%9.2f\n", total_income);
                                printf("\t\tLess relief: -$%9.2f\n", total_relief);
                                printf("Total taxable amount\t   :  $%9.2f\n", taxable_amount);
                                printf("\t\tLess rebate: -$%9.2f\n", total_rebate);
                                printf("\n");
                                printf("Amount payment\t\t   :  $%9.2f\n", amount_payment);
                              }
                          printf("\n");

                          printf("**If you don't use this Tax Advisor Program, please press D to QUIT.\n\n\n");
                          break;

            case 'd'    :
            case 'D'    : printf("\nThank You... Have a Nice Day!");
                          printf("\n\n");
                          break;

            default        : printf("\nInvalid Choice! Please try again...");
                          printf("\n\n");
        }
    }
    printf("\n\n");
}



因為你所訂的 name 是 2 dimension, 而你所 gets 的卻是 1 dimension, 所以不能被儲存
作者: 无我不在    时间: 2009-1-11 07:07 AM
标题: 还是不能运作
我在每个variable都加了作用于是为了让它记录在哪个位子(空间)。可是还是没办法运行.

[quote]
原帖由 无我不在 于 2009-1-10 11:23 PM 发表
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
    int code=37, i=-1;
    char choice=0, icno_search[8];
    char name[10][50]={""}, icno[10][8]={""}, DOB[10][10]={""}, sex[10]={""};
    float total_income[10]={0}, total_relief[10]={0}, total_rebate[10]={0}, pre_payment[10]={0}, taxable_amount[10]={0};
    float amount_payment[10]={0};
   
    while(choice!='D'&& choice!='d')
    {
        printf("Tax Advisor Program\n");
        printf("(A)\tDisplay taxation rate\n");
        printf("(B)\tInput tax payer's particulars\n");
        printf("(C)\tCompute and display tax payable\n");
        printf("(D)\tQuit\n");
        printf("Enter Choice:  ");
        flushall();
        scanf("%c", &choice);

        switch(choice)
        {
            case 'a'    :
            case 'A'    : printf("\n\nTax Rate Information Table\n");
                          printf("==========================");
                          printf("\n\t\tIncome\t\tRate\n");
                          printf("\t\t$\t\t(%c)\n", code);
                          printf("On the frist\t20,000\t\t0\n");
                          printf("On the next\t10,000\t\t3.5\n");
                          printf("On the next\t10,000\t\t5.5\n");
                          printf("On the next\t40,000\t\t8.5\n");
                          printf("On the next\t80,000\t\t14\n");
                          printf("On the next\t160,000\t\t17\n");
                          printf("Above\t\t320,000\t\t20\n");
                          printf("\n\n");
                          break;

            case 'b'    :
            case 'B'    : i = i + 1;
                          printf("\n\n");
                          printf("Fill Your Descriptions in the following\n");
                          printf("=======================================");
                          printf("\nEnter NRIC no.: ");
                          flushall();
                          scanf("%s", &icno{i});
                          printf("Enter Name: ");
                          flushall();
                          gets(name
{i});
                          printf("Enter Date of Birth(DD-MM-YYYY): ");
                          flushall();
                          gets(DOB
{i});
                          printf("Enter Sex(M/F): ");
                          flushall();
                          scanf("%c", &sex
{i});
                          printf("Enter Total Income: $");
                          flushall();
                          scanf("%f", &total_income
{i});
                          printf("Enter Total Relief: $");
                          flushall();
                          scanf("%f", &total_relief
{i});
                          printf("Enter Total Rebate: $");
                          flushall();
                          scanf("%f", &total_rebate
{i});
                          printf("\n");

                          printf("**To compute and display your amount payment, please press C to continue.\n\n\n");
                                             
                          pre_payment
{i} = total_income{i} - total_relief{i};

                          if(pre_payment
{i}>=0 && pre_payment{i}<20000)
                          {
                              taxable_amount
{i} = pre_payment{i} * 0;
                          }
                          else
                          {
                              if(pre_payment
{i} > 20000 && pre_payment{i} <= 30000)
                              {
                                  taxable_amount
{i} = 0 + (pre_payment{i}-20000) * 0.035;
                              }
  ......
                                 ......



[ 本帖最后由 无我不在 于 2009-1-11 07:13 AM 编辑 ]
作者: 无我不在    时间: 2009-1-11 07:17 AM
我在google搜索过了,ARRAY的示范都已经分别指定的位子(空间),不然就是用for loop (exp. for(i=0; i<10, i=i+1) ),所以 i 能自动增加,所以每当一个input就有新的位子(空间)记入起来。

可是,我没办法每当我输入新的input,也不能记入新的位子(空间)。也没有 i=i+1 去自动增加位子(空间)的数量。

char[x][y] = {""}         x ==> number of store ; y ==> size of character
**difference with int and float**
int[x][y] = {"")
float[x][y] = {""}         x ==> number of row in store ; y ==> number of column in store

这样可以说明,我这篇program是用 2D char 和 1D int/float 了。

我现在不知道什么方法储存input。
作者: Super-Tomato    时间: 2009-1-11 02:20 PM
原帖由 无我不在 于 2009-1-11 07:17 AM 发表
我在google搜索过了,ARRAY的示范都已经分别指定的位子(空间),不然就是用for loop (exp. for(i=0; i number of store ; y ==> size of character
**difference with int and float**
int[x][y] = {"")
fl ...



方法用錯了, 這個例子你去參考變通

#include <stdio.h>

int main()
{
    char name[3][50] = {};
    int age[3];

    for(int a=0; a<3; a++)
    {
        printf("\nPlease enter name %d : ", a+1);
        scanf("%s", name[a]);
        printf(" Please enter %s's age : ", name[a]);
        scanf("%d", &age[a]);
    }

    printf("\nSecond record is : %s and %d years old", name[1], age[1]);
    return 0;
}


例子都有了, 希望改好之後把完整的coding放上來讓其他人學習
p/s: 儘量不要用 i, b, u 做為變數貼在這裡, 不然會被默認為斜體, 粗體和底線

[ 本帖最后由 Super-Tomato 于 2009-1-11 02:41 PM 编辑 ]
作者: MercyGodlikE    时间: 2009-1-11 03:56 PM
为什么总觉得C++的格式很复杂
(头脑过于简单了)
作者: 无我不在    时间: 2009-1-11 04:08 PM
标题: 回复 #5 Super-Tomato 的帖子
这个列子会要求重复input。到了第四次input才会结束for loop的。

我的作业要求输入一次资料后回到menu,然后再做选择。然而,第二次输入资料,可以自动地记入另一个空间。最后,客户以IC搜索(strcmp),找回资料。


还是不行啊~~~都不能 a=a+1,自动记入新的储存空间。

我还是认为自己不是学programming的料。一个languague就让我瓶颈了,而且只是入门知识罢了。苦恼

[ 本帖最后由 无我不在 于 2009-1-11 04:32 PM 编辑 ]
作者: 无我不在    时间: 2009-1-11 04:25 PM
标题: 回复 #6 MercyGodlikE 的帖子
你学习进展如何了啊?
作者: Super-Tomato    时间: 2009-1-11 05:06 PM
原帖由 无我不在 于 2009-1-11 04:08 PM 发表
这个列子回要求重复input。到了第四次input才会结束for loop的。

我的作业要求输入一次资料后回到menu,然后再做选择。然而,第二次输入资料,可以自动地记入另一个空间。最后,客户以IC搜索(strcmp),找回 ...



你怎麼沒變通啊, 循環和自己遞增不都是由一個 variable 控制的嗎??
難道最基本的 + 你都忘了嗎?? 之前的那些 coding 你是怎麼寫出來的??


#include <stdio.h>

int main()
{
    char name[3][50] = {}, choice;
    int age[3], i=0;

    while(choice!='D'&& choice!='d')
    {
        choice = NULL;
        printf("Tax Advisor Program\n");
        printf("(A)\tDisplay taxation rate\n");
        printf("(B)\tInput tax payer's particulars\n");
        printf("(C)\tCompute and display tax payable\n");
        printf("(D)\tQuit\n\n");
        printf("Enter Choice:  ");
        scanf("%s", &choice);

        switch(choice)
        {
            case 'A':
            case 'a':
                printf("Please enter name %i : ", i+1);
                scanf("%s", name[ i ]);
                printf("Please enter %s's age : ", name);
                scanf("%i", &age[ i ]);
                i++;
                break;
        }

        printf("\n\n");
    }

    printf("\nSecond record is : %s and %i years old", name[1], age[1]);
    return 0;
}
作者: 无我不在    时间: 2009-1-11 05:26 PM
原帖由 Super-Tomato 于 2009-1-11 05:06 PM 发表
switch(choice)
        {
            case 'A':
            case 'a':
                printf("Please enter name %i : ", i+1);
                scanf("%s", name[ i ]);
                printf("Please enter %s's age : ", name);
                scanf("%i", &age[ i ]);
                i++;
                break;
        }


%i 什么作用,我运行出现乱码。是不是%d?

**我越写越自己乱了。抱歉

[ 本帖最后由 无我不在 于 2009-1-11 05:30 PM 编辑 ]
作者: Super-Tomato    时间: 2009-1-11 05:36 PM
原帖由 无我不在 于 2009-1-11 05:26 PM 发表


%i 什么作用,我运行出现乱码。是不是%d?

**我越写越自己乱了。抱歉



嗯.. 用 %d 代表 decimal, 你不要用 %i, 因為我用的編譯器可以支援 %i
去測試你就知道了
作者: 无我不在    时间: 2009-1-11 05:47 PM
有一点进展了。

新的问题:
现在能储存多个了,可是不能显示之前的资料。比如说,第三次输入,回到menu要求显示第一份资料,结果倒回menu。我继续要求显示资料,这回要求第三份资料,结果显示成功。这说明第三次的资料覆盖了之前的资料,还是我在printf的时候没把空间分花清楚?
作者: 无我不在    时间: 2009-1-11 05:52 PM
是不是在case ‘C’ 出现问题?还是在case 'B'的算术中的variable不能存储之前的资料?因为只能出现最后一次的资料。

case 'b'    :
            case 'B'    : printf("\n\n");
                          printf("Fill Your Descriptions in the following\n");
                          printf("=======================================");
                          printf("\n[S/N %d] Enter NRIC no.: ",a=a+1);
                          flushall();
                          scanf("%s", &icno[a]);
                          printf("[S/N %d] Enter Name: ", a);
                          flushall();
                          gets(name[a]);
                          printf("[S/N %d] Enter Date of Birth(DD-MM-YYYY): ", a);
                          flushall();
                          gets(DOB[a]);
                          printf("[S/N %d] Enter Sex(M/F): ", a);
                          flushall();
                          scanf("%c", &sex[a]);
                          printf("[S/N %d] Enter Total Income: $", a);
                          flushall();
                          scanf("%f", &total_income[a]);
                          printf("[S/N %d] Enter Total Relief: $", a);
                          flushall();
                          scanf("%f", &total_relief[a]);
                          printf("[S/N %d] Enter Total Rebate: $", a);
                          flushall();
                          scanf("%f", &total_rebate[a]);
                          printf("\n");

                          printf("**To compute and display your amount payment, please press C to continue.\n\n\n");
                                             
                          pre_payment[a] = total_income[a] - total_relief[a];

                          if(pre_payment[a]>=0 && pre_payment[a]<20000)
                          {
                              taxable_amount[a] = pre_payment[a] * 0;
                          }
                          else
                          {
                              if(pre_payment[a] > 20000 && pre_payment[a] <= 30000)
                              {
                                  taxable_amount[a] = 0 + (pre_payment[a]-20000) * 0.035;
                              }
                              else
                              {
                                  if(pre_payment[a] > 30000 && pre_payment[a] <= 40000)
                                  {
                                      taxable_amount[a] = 350 + (pre_payment[a]-30000) * 0.055;
                                  }
                                  else
                                  {
                                      if(pre_payment[a] > 40000 && pre_payment[a] <= 80000)
                                      {
                                          taxable_amount[a] = 900 + (pre_payment[a]-40000) * 0.085;
                                      }
                                      else
                                      {
                                          if(pre_payment[a] > 80000 && pre_payment[a] <= 160000)
                                          {
                                              taxable_amount[a] = 4300 + (pre_payment[a]-80000) * 0.14;
                                          }
                                          else
                                          {
                                              if(pre_payment[a] > 160000 && pre_payment[a] <= 320000)
                                              {
                                                  taxable_amount[a] = 15500 + (pre_payment[a]-160000) * 0.17;
                                              }
                                              else
                                              {
                                                  taxable_amount[a] = 42700 + (pre_payment[a]-320000) * 0.2;
                                              }
                                          }
                                      }
                                  }
                              }
                          }
                          amount_payment[a] = taxable_amount[a] - total_rebate[a];
                          break;

            case 'c'    :
            case 'C'    : printf("Enter Your NRIC: ");
                          flushall();
                          gets(icno_search);
                           
                            if(strcmp(icno[a], icno_search) == 0)
                            {
                                printf("\n\nYour Total Amount Payment");
                                printf("\n=========================");
                                printf("\nNRIC\t\t\t   : %s", icno[a]);
                                printf("\nName\t\t\t   : %s", name[a]);
                                printf("\nDate of Brith\t\t   : %s\n", DOB[a]);
                                printf("Sex\t\t\t   : %c\n\n", sex[a]);
                                printf("Total income\t\t   :  $%9.2f\n", total_income[a]);
                                printf("\t\tLess relief: -$%9.2f\n", total_relief[a]);
                                printf("Total taxable amount\t   :  $%9.2f\n", taxable_amount[a]);
                                printf("\t\tLess rebate: -$%9.2f\n", total_rebate[a]);
                                printf("\n");
                                printf("Amount payment\t\t   :  $%9.2f\n", amount_payment[a]);
                              }
                          printf("\n");

                          printf("**If you don't use this Tax Advisor Program, please press D to QUIT.\n\n\n");
                          break;

[ 本帖最后由 无我不在 于 2009-1-11 05:58 PM 编辑 ]
作者: Super-Tomato    时间: 2009-1-11 06:03 PM
原帖由 无我不在 于 2009-1-11 05:52 PM 发表
是不是在case ‘C’ 出现问题?还是在case 'B'的算术中的variable不能存储之前的资料?因为只能出现最后一次的资料。

            case 'C'    : printf("Enter Your NRIC: ");
                          flushall();
                          gets(icno_search);
                           
                            if(strcmp(icno[a], icno_search) == 0)
                            {
                                printf("\n\nYour Total Amount Payment");
                                printf("\n=========================");
                                printf("\nNRIC\t\t\t   : %s", icno[a]);
                                printf("\nName\t\t\t   : %s", name[a]);
                                printf("\nDate of Brith\t\t   : %s\n", DOB[a]);
                                printf("Sex\t\t\t   : %c\n\n", sex[a]);
                                printf("Total income\t\t   :  $%9.2f\n", total_income[a]);
                                printf("\t\tLess relief: -$%9.2f\n", total_relief[a]);
                                printf("Total taxable amount\t   :  $%9.2f\n", taxable_amount[a]);
                                printf("\t\tLess rebate: -$%9.2f\n", total_rebate[a]);
                                printf("\n");
                                printf("Amount payment\t\t   :  $%9.2f\n", amount_payment[a]);
                              }
                          printf("\n");

                          printf("**If you don't use this Tax Advisor Program, please press D to QUIT.\n\n\n");
                          break;


你想想看這行 icno_search 是在和哪個資料做比對??
作者: 无我不在    时间: 2009-1-11 06:09 PM
原帖由 Super-Tomato 于 2009-1-11 06:03 PM 发表


你想想看這行 icno_search 是在和哪個資料做比對??

= =知道了,他只能和最后一次的资料对比罢了。
怎么解决?逻辑有点乱了。给我时间想想。
作者: 无我不在    时间: 2009-1-11 06:36 PM
标题: 这份是我之前能能正常运作的作业。 strcmp在两份作业中有什么不同?
case 7 :printf("\n\tSearch by Number:");
                printf("\n\tEnter Mark:");
                scanf("%d", &srchmark);                                                               //search by %d variable
               
                printf("\n\tS/No\tName\tMark");
                printf("\n\t**********************************************");
                for(i=0; i<5; i=i+1)
                {
                    if(mark{i}==srchmark)
                    {
                        printf("\n\t%d\t%s\t%d", i, name{i}, mark{i});
                    }
                }
                printf("\n\t**********************************************");
                printf("\n");
                break;

        case 8 :printf("\n\tSearch by character:");
                printf("\n\tEnter Name:");
                flushall();
                gets(srchname);                                                      //search by %s variable

                printf("\n\tS/No\tName\tMark");
                printf("\n\t**********************************************");
                for(i=0; i<5; i=i+1)
                {
                    if(strcmp(name{i}, srchname) == 0)                         //also use strcmp to searching function.
                    {
                        printf("\n\t%d\t%s\t%d", i, name{i}, mark{i});
                    }
                }
                printf("\n\t**********************************************");
                printf("\n");
                break;


[ 本帖最后由 无我不在 于 2009-1-11 06:54 PM 编辑 ]
作者: goodday    时间: 2009-1-11 07:04 PM
番茄 很努力也~~~



加油咯
作者: 无我不在    时间: 2009-1-11 07:08 PM
标题: 回复 #17 goodday 的帖子
他很努力的在帮忙我。真的要谢谢他先。

我是不是不适合学programming?到现在还想不到方法。。。

版主不会C++吗?

[ 本帖最后由 无我不在 于 2009-1-11 07:17 PM 编辑 ]
作者: goodday    时间: 2009-1-11 07:20 PM
我的 c++ 还回给老师咯
改还会 
写就 要查书咯

你的 我没时间帮忙 想 
很吃时间咯



你欠 番茄 一餐咯


作者: goodday    时间: 2009-1-11 07:22 PM
没有适合不适合的 programmer 
只怕没行动的 programmer

你会 找 google 问人 年有行动咯

努力吧 
作者: Super-Tomato    时间: 2009-1-11 08:33 PM
不知道為何樓主喜歡用 {i} , 這個和 [ i ] 是不同意義的
作者: 无我不在    时间: 2009-1-11 09:00 PM
标题: 回复 #21 Super-Tomato 的帖子
<-- 【不见了】 会自动消失叻,我也不知道为什么。。。

[ 本帖最后由 无我不在 于 2009-1-11 09:02 PM 编辑 ]
作者: 无我不在    时间: 2009-1-12 06:23 AM
Tomato 你有解决的方法吗?我搜索整晚了em0027

现在去上课,下午再回家。
作者: Super-Tomato    时间: 2009-1-12 11:46 AM
原帖由 无我不在 于 2009-1-12 06:23 AM 发表
Tomato 你有解决的方法吗?我搜索整晚了em0027

现在去上课,下午再回家。



不明白你是說哪裡有問題, 如果是搜索部分有問題的話, 建議你先列印出你要搜索的資料, 如


                printf("\n\t**********************************************");
                for(i=0; i<5; i=i+1)
                {
                        printf("\n\t%d\t%s\t%d", i, name{i}, mark{i});
                }
                printf("\n\t**********************************************");


要是這些列印出來的資料都沒問題, 那麼才進行 strcmp

p/s: 要是想增加可閱讀性和避免自己搞亂的話, 建議你使用function把每項功能分開
作者: 无我不在    时间: 2009-1-16 09:30 PM
标题: 能运行的Coding(一)
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
        int code=37, a=0, f=0, stuff_password=0, customer_password[10]={0}, password_input=0, check_flag=0;
        char choice=0, icno_search[15]={""};
        char name[10][50]={""}, icno[10][15]={""}, DOB[10][15]={""}, sex[10]={""};
        float total_income[10]={0}, total_relief[10]={0}, total_rebate[10]={0}, pre_payment[10]={0}, taxable_amount[10]={0};
        float amount_payment[10]={0};
        
        while(choice!='D'&& choice!='d')
        {
                printf("Tax Advisor Program\n");
                printf("(A)  Display taxation rate\n");
                printf("(B)  Input tax payer's particulars\n");
                printf("(C)  Compute and display tax payable\n");
                printf("(D)  Quit\n");
                printf("\n(Z)  For STUFF only\n");
                printf("\n\tEnter Choice:  ");
                flushall();
                scanf("%c", &choice);

                switch(choice)
                {
                        case 'a'        :
                        case 'A'        : printf("\n\nTax Rate Information Table\n");
                                                  printf("==========================");
                                                  printf("\n\t\tIncome\t\tRate\n");
                                                  printf("\t\t$\t\t(%c)\n", code);
                                                  printf("On the frist\t20,000\t\t0\n");
                                                  printf("On the next\t10,000\t\t3.5\n");
                                                  printf("On the next\t10,000\t\t5.5\n");
                                                  printf("On the next\t40,000\t\t8.5\n");
                                                  printf("On the next\t80,000\t\t14\n");
                                                  printf("On the next\t160,000\t\t17\n");
                                                  printf("Above\t\t320,000\t\t20\n");
                                                  printf("\n\n");
                                                  break;

                        case 'b'        :
                        case 'B'        : a=a+1;
                                                  printf("\n\n");
                                                  printf("Fill Your Descriptions in the following\n");
                                                  printf("=======================================");
                                                  printf("\n[S/N %d] Enter NRIC no.: ",a);
                                                  flushall();
                                                  scanf("%s", &icno[a]);
                                                  printf("[S/N %d] Enter Name: ", a);
                                                  flushall();
                                                  gets(name[a]);
                                                  printf("[S/N %d] Enter Date of Birth(DD-MM-YYYY): ", a);
                                                  flushall();
                                                  gets(DOB[a]);
                                                  printf("[S/N %d] Enter Sex(M/F): ", a);
                                                  flushall();
                                                  scanf("%c", &sex[a]);
                                                  printf("[S/N %d] Enter Total Income: $", a);
                                                  flushall();
                                                  scanf("%f", &total_income[a]);
                                                  printf("[S/N %d] Enter Total Relief: $", a);
                                                  flushall();
                                                  scanf("%f", &total_relief[a]);
                                                  printf("[S/N %d] Enter Total Rebate: $", a);
                                                  flushall();
                                                  scanf("%f", &total_rebate[a]);
                                                  printf("\n");
                                                  printf("[S/N %d] Setting Your PASSWORD (6 Digits): ", a);
                                                  flushall();
                                                  scanf("%d", &customer_password[a]);
                                                  printf("\n\n");

                                                  printf("**To compute and display your amount payment, please press C to continue.\n\n\n");
                                                                                          
                                                  pre_payment[a] = total_income[a] - total_relief[a];

[ 本帖最后由 无我不在 于 2009-1-16 09:50 PM 编辑 ]
作者: 无我不在    时间: 2009-1-16 09:32 PM
标题: 【续】能运行的Coding(二)
if(pre_payment[a]>=0 && pre_payment[a]<20000)
                                                  {
                                                          taxable_amount[a] = pre_payment[a] * 0;
                                                  }
                                                  else
                                                  {
                                                          if(pre_payment[a] > 20000 && pre_payment[a] <= 30000)
                                                          {
                                                                  taxable_amount[a] = 0 + (pre_payment[a]-20000) * 0.035;
                                                          }
                                                          else
                                                          {
                                                                  if(pre_payment[a] > 30000 && pre_payment[a] <= 40000)
                                                                  {
                                                                          taxable_amount[a] = 350 + (pre_payment[a]-30000) * 0.055;
                                                                  }
                                                                  else
                                                                  {
                                                                          if(pre_payment[a] > 40000 && pre_payment[a] <= 80000)
                                                                          {
                                                                                  taxable_amount[a] = 900 + (pre_payment[a]-40000) * 0.085;
                                                                          }
                                                                          else
                                                                          {
                                                                                  if(pre_payment[a] > 80000 && pre_payment[a] <= 160000)
                                                                                  {
                                                                                          taxable_amount[a] = 4300 + (pre_payment[a]-80000) * 0.14;
                                                                                  }
                                                                                  else
                                                                                  {
                                                                                          if(pre_payment[a] > 160000 && pre_payment[a] <= 320000)
                                                                                          {
                                                                                                  taxable_amount[a] = 15500 + (pre_payment[a]-160000) * 0.17;
                                                                                          }
                                                                                          else
                                                                                          {
                                                                                                  taxable_amount[a] = 42700 + (pre_payment[a]-320000) * 0.2;
                                                                                          }
                                                                                  }
                                                                          }
                                                                  }
                                                          }
                                                  }
                                                  amount_payment[a] = taxable_amount[a] - total_rebate[a];
                                                  break;

                        case 'c'        :
                        case 'C'        : printf("\n\tEnter Your NRIC: ");
                                                  flushall();
                                                  gets(icno_search);
                                                  printf("\tEnter Your PASSWORD: ");
                                                  flushall();
                                                  scanf("%d", &password_input);

                                                  check_flag=0;
                                                  for(f=0; f<10; f=f+1)
                                                  {
                                                                if((strcmp(icno[f], icno_search) == 0) && (customer_password[f] == password_input))
                                                                {
                                                                        check_flag = 1;
                                                                        break;
                                                                }
if(check_flag == 1)
                                                  {
                                                                printf("\n\nYour Total Amount Payment");
                                                                printf("\n=========================");
                                                                printf("\nYour account no.: %d", f);
                                                                printf("\nNRIC\t\t\t   : %s", icno
[f]);
                                                                printf("\nName\t\t\t   : %s", name
[f]);
                                                                printf("\nDate of Brith\t\t   : %s\n", DOB
[f]);
                                                                printf("Sex\t\t\t   : %c\n\n", sex
[f]);
                                                                printf("Total income\t\t   :  $%9.2f\n", total_income
[f]);
                                                                printf("\t\tLess relief: -$%9.2f\n", total_relief
[f]);
                                                                printf("Total REMAIN income\t   :  $%9.2f\n", pre_payment
[f]);
                                                                printf("\n");
                                                                printf("Total taxable amount\t   :  $%9.2f\n", taxable_amount
[f]);
                                                                printf("\t\tLess rebate: -$%9.2f\n", total_rebate
[f]);
                                                                printf("\n");
                                                                printf("AMOUNT PAYMENT\t\t   :  $%9.2f\n", amount_payment
[f]);

                                                               
                                                  }
                                                  else
                                                  {
                                                                printf("No Record Found! Please try again...\n");
                                                  }
                                
                                                  printf("\n");
                                                  printf("**If you don't use this Tax Advisor Program, please press D to QUIT.\n\n\n");
                                                  break;

                        case 'd'        :
                        case 'D'        : printf("\nThank You... Have a Nice Day!");
                                                  printf("\n\n");
                                                  break;


[ 本帖最后由 无我不在 于 2009-1-16 09:50 PM 编辑 ]
作者: 无我不在    时间: 2009-1-16 09:36 PM
标题: 【续】能运行的Coding(三)
case 'z'        :
                        case 'Z'        : printf("\n\tPassword: ");
                                                  scanf("%d", &stuff_password);
                                                  if(stuff_password == 123456)
                                                  {
                                                        printf("\n\tS/N\tNRIC\t\tName\t\tTAX Payment\tPassword");
                                                        printf("\t\t******************************************************************");
                                                        for(f=1; f<10; f=f+1)
                                                          {
                                                                printf("\n\t%d\t%s\t%s\t%8.2f\t%d", f, icno[f], name[f], amount_payment[f], customer_password[f]);
                                                          }
                                                        printf("\n\t******************************************************************");
                                                        printf("\n\n");
                                                  }
                                                  else
                                                  {
                                                          printf("Invalid Password. Please try again....");
                                                  }
                                                  break;
      
                        default                : printf("\nInvalid Choice! Please try again...");
                                                  printf("\n\n");
                }
        }
        printf("\n\n");
}

[ 本帖最后由 无我不在 于 2009-1-16 09:40 PM 编辑 ]
作者: 无我不在    时间: 2009-1-16 09:56 PM
标题: 请教高手!
进入Z case,系统要求:
PASSWORD: 123456

在switch_case Z那里,我想增加一个效果。就是当你输入PASSWORD时,如何隐藏PASSWORD?比如说,

进入Z case,
PASSWORD:******         // input 改为*码


还有多一个效果想请教。就是,如何更改字体的颜色、范围背景颜色 和 大小?

[ 本帖最后由 无我不在 于 2009-1-16 09:59 PM 编辑 ]
作者: goodhermit95    时间: 2009-1-16 10:43 PM
Textbox的话就直接换Properties
textBox1->PasswordChar == "*";
作者: 无我不在    时间: 2009-1-16 11:00 PM
标题: 回复 #29 goodhermit95 的帖子
google里的textbox例子不适用在这个作业。
除了你那方法,还有例子是这样的:
        int i = 0;
        char ch;
        char password[20];
        do
        {
                ch = getch();
                cerr<<"*";
                password[i++] = ch;
        }
        while(ch != '\r');

textbox 要用什么library?
我使用Window visual 2008的, Dev C++的libary不能通用?

你有没有link给我参考?


[ 本帖最后由 无我不在 于 2009-1-16 11:28 PM 编辑 ]
作者: Super-Tomato    时间: 2009-1-16 11:50 PM
原帖由 无我不在 于 2009-1-16 09:56 PM 发表
进入Z case,系统要求:
PASSWORD: 123456

在switch_case Z那里,我想增加一个效果。就是当你输入PASSWORD时,如何隐藏PASSWORD?比如说,

进入Z case,
PASSWORD:******         // input 改为*码

...



那麼你就要使用 conio.h 然後配合 getch 取得使用者所輸入的文字之後儲存起來, 之後再用 putch 輸出 * 到畫面

至於字體顏色的改變你可以找一下之前的帖子, 我回過了
作者: Jay1515Jay    时间: 2009-1-17 12:28 AM
番茄整天帮人
好好人啊em0034
作者: 无我不在    时间: 2009-1-17 09:47 AM
case 'z'        :
case 'Z'        : while(ch != '\r')                                  //\r是什么?
                  {
                       ch = getch();
                        cerr<<"*";                                          //cerr是什么?需要declare吗?
                        stuff_password[i++] = ch;
                        printf("\n\tPassword: ");
                        gets(stuff_password);
                   }
作者: Super-Tomato    时间: 2009-1-17 10:41 AM
原帖由 无我不在 于 2009-1-17 09:47 AM 发表
case 'z'        :
case 'Z'        : while(ch != '\r')                                  //\r是什么?
                  {
                       ch = getch();
                        cerr<<"*";                                          //cerr是什么?需要declare吗?
                        stuff_password[i++] = ch;
                        printf("\n\tPassword: ");
                        gets(stuff_password);
                   }



你要会抄之前先学会看 while 就是循环,要跳出循环当然就是要判断使用者是否输入了 Enter

cerr 的使用说明请看
http://msdn.microsoft.com/en-us/library/6xwbdak2(VS.80).aspx

以上例子你不明白的话,请先明白我所说的 getch 和 putch 使用方法,而且你的那段 coding 也不完整欠缺了 backspace 删除 * 的方式
作者: 无我不在    时间: 2009-1-17 12:52 PM
标题: 回复 #34 Super-Tomato 的帖子
【成功运行】

我的visual 2008不能用iostream叻。
所以我用这个function。可是不好写……

参考:http://hi.baidu.com/toyourside/b ... 56088f47106493.html

char* get_password(const   char   *prompt)   
{   
        static char buffer[128];   
        int p=0;   
        char letter=NULL;   
        printf(prompt);  
        while((p<127)&&(letter!='\r'))   
        {   
                letter=getch();   
                if(letter==BACKSPACE)   
                {   
                        if(p>0)   
                        {   
                                buffer[--p]=NULL;   
                                putchar(BACKSPACE);   
                                putchar('   ');   
                                putchar(BACKSPACE);   
                        }   
                        else
                        {
                                putchar(7);  
                        }
                }   
                else if(letter!='\r')   
                {   
                        buffer[p++]=letter;   
                        putchar('*');   
                }   
        }   
        return   (buffer);   
}   

【void main里】
case 'z'        :
case 'Z'        : printf("\n\t");
                     stuff_password = get_password("Enter PASSWORD: ");
                                                
                     if(strcmp(stuff_password, "iloveyou") == 0)
                     {
                             printf("\n\n\tS/N\tNRIC\t\tName\t\tTAX Payment\tPassword");
                             printf("\t\t******************************************************************");
                             for(i=1; i<10; i=i+1)
                             {
                              printf("\n\t%d\t%s\t%s\t%8.2f\t%s", i, icno, name, amount_payment, customer_password);
                               }
                              printf("\n\t******************************************************************");
                              printf("\n\n");
                              }
                       }


[ 本帖最后由 无我不在 于 2009-1-17 12:57 PM 编辑 ]
作者: 无我不在    时间: 2009-1-17 02:10 PM
标题: 回复 #31 Super-Tomato 的帖子
你之前的文章沉到哪里了? T.T
改变字体颜色大小?是不是用SetConsoleTextAttribute?我是想在指定的范围做颜色效果,可是我还没学过。上网搜索,大部分例子都是用function的。
#define BLACK 0
#define BLUE 1
#define GREEN 2
#define CYAN 3
#define RED 4
#define MAGENTA 5
#define BROWN 6
#define LIGHTGREY 7
#define DARKGREY 8
#define LIGHTBLUE 9
#define LIGHTGREEN 10
#define LIGHTCYAN 11
#define LIGHTRED 12
#define LIGHTMAGENTA 13
#define YELLOW 14
#define WHITE 15
#define BLINK 128

还是system("color 0e");?  可是影响到整篇作业的颜色。
   1. 0 = Black       8 = Gray
   2. 1 = Blue        9 = Light Blue
   3. 2 = Green       A = Light Green
   4. 3 = Aqua        B = Light Aqua
   5. 4 = Red         C = Light Red
   6. 5 = Purple      D = Light Purple
   7. 6 = Yellow      E = Light Yellow
   8. 7 = White       F = Bright White

[ 本帖最后由 无我不在 于 2009-1-17 02:22 PM 编辑 ]
作者: Super-Tomato    时间: 2009-1-17 07:51 PM
原帖由 无我不在 于 2009-1-17 12:52 PM 发表
【成功运行】

我的visual 2008不能用iostream叻。
所以我用这个function。可是不好写……

参考:http://hi.baidu.com/toyourside/b ... 56088f47106493.html

char* get_password(const ...



iostream 是 C++ 的 header,  Visual C++ 怎麼可能會不支援呢
那個 get_password 函數怎麼會不好寫啊, 是你還沒去了解程式的應用意義

http://www.super-tomato.net/download/Mask.exe


http://www.jbtalks.cc/thread-442065-1-4.html
作者: 无我不在    时间: 2009-1-17 11:37 PM
标题: 回复 #37 Super-Tomato 的帖子
其实我学校教的很有限。
现在都是自己在爬文章和例子。基础也不稳。

每次我开的coding都是属于 .c file(学校教的)来的。这样是不是会影响到我不能用iostream呢?因为我拷贝你的coding,都不能运行。还是要下载一些补丁啊?
iostream / windows.h 都会显示错误的。
作者: Super-Tomato    时间: 2009-1-18 12:11 AM
原帖由 无我不在 于 2009-1-17 11:37 PM 发表
其实我学校教的很有限。
现在都是自己在爬文章和例子。基础也不稳。

每次我开的coding都是属于 .c file(学校教的)来的。这样是不是会影响到我不能用iostream呢?因为我拷贝你的coding,都不能运行。还是要 ...



昏~~~

.c 當然就只是單純的只能運用 C, 而 .cpp 才能兩者兼用

不過你要做到的 * 單使用 C 就可以做到,但是輸出顏色就必需使用 C++ 的 library
作者: 无我不在    时间: 2009-1-18 12:17 AM
标题: 回复 #39 Super-Tomato 的帖子
哇哈哈,难怪很多coding例子都不能运行。

努力爬文章中……不明白再再发问。

不好意识啊。
作者: goodhermit95    时间: 2009-1-18 11:45 AM
C++ 好像要用到很多API的?我在做3D,要用C++来做(Dark GDK 听过吗)
我看他们restart program都要API
作者: 无我不在    时间: 2009-1-18 12:33 PM
标题: 回复 #41 goodhermit95 的帖子
我老师提过。
他说,如果想试试的话,下载他的patch就可以使用了。而且还有自带很多model,已经可以自己开发类似CS的游戏的。
而且还提供coding参考。
作者: goodhermit95    时间: 2009-1-18 12:36 PM
标题: 回复 #42 无我不在 的帖子
是Templete吗?
作者: 无我不在    时间: 2009-1-18 12:54 PM
标题: 回复 #43 goodhermit95 的帖子
erm……详细的自然就不清楚也不懂了。因为我还是初学者叻。

我学校新课程,以C++、Dark GDK、adobe PS为基础的。
http://www.nyp.edu.sg/sidm/gamecourse.html

现在新加坡的Game & Media正在加速发展哦。

可是老实说,programmer还是在data base方面发展比较稳定,尤其用在商业上。
作者: goodhermit95    时间: 2009-1-18 12:58 PM
标题: 回复 #44 无我不在 的帖子
em0003
DarkGDK 我学着
作者: Jay1515Jay    时间: 2009-1-18 01:49 PM
本来想下载来试试做game的
200MB++下次才学
电脑没有位了
em0054
作者: goodhermit95    时间: 2009-1-18 02:29 PM
标题: 回复 #46 Jay1515Jay 的帖子
又来了……这个也是有点难度,只是我拿来弄3D学校……
作者: Jay1515Jay    时间: 2009-1-18 02:31 PM
原帖由 goodhermit95 于 2009-1-18 02:29 PM 发表
又来了……这个也是有点难度,只是我拿来弄3D学校……

Dark是制作3D的咩?
我以为load 3D file然后coding game
作者: goodhermit95    时间: 2009-1-18 02:44 PM
标题: 回复 #48 Jay1515Jay 的帖子
难度就在于Coding 3D的物件跟Program在一起

不过Dark GDK真的很好用
作者: goodhermit95    时间: 2009-1-18 03:48 PM
不知道他们的地上是怎么弄的(3D World Studio Samples)
作者: 无我不在    时间: 2009-1-18 04:42 PM
Dark GDK 2D 3D 都行。首要条件是C++.
作者: 无我不在    时间: 2009-1-23 11:01 PM
标题: 想请教高手。
应用: 2D Array in password setting with display '*' sign. (.c language only)

状况:通常在网路申请新户口时,官方会要求设定密码,同时要求输入多一回以确定你的密码。如果不相同,系统要求重新输入。需要记入10个密码。

目前的问题:不能储存以后的password。

#include <stdio.h>
#include <string.h>
void main()
{
        char password[10][15]={""}, password_check[15]={""};
        char letter={""};
        int choice=0, a=0, i=0, p=0, check_flag=0;
       
        while(choice!=3)
        {
                printf("1. Set Password\n");
                printf("2. Display all 10 passwords\n");
                printf("3. Edn program\n\n");
                printf("Enter Choice: ");
                scanf("%d", &choice);
                printf("\n");

                switch(choice)
                {
                        case 1 :p++;
                                        letter=NULL;
                                        printf("Set Password[%d]: ", p);
                                        while(i<14 && letter!='\r')
                                        {
                                                letter = getch();
                                                if(letter==8)   
                                                {   
                                                        password[p][--i]=NULL;   
                                                        putchar(8);   
                                                        putchar('   ');   
                                                        putchar(8);   
                                                }
                                                else
                                                {
                                                        if(letter!="\r")
                                                        {
                                                                password[p][i++]=letter;
                                                                putchar('*');
                                                        }
                                                }
                                        }
                                        printf("\n\n");
                                        break;

                        case 2 :for(a=1; a<10; a++)
                                        {
                                                printf("\nPassword [%d] : %s", a, password[a]);
                                        }
                                        printf("\n\n");
                                        break;

                        default:printf("Program End!\n\n");
                }
        }       
}
作者: Super-Tomato    时间: 2009-1-24 12:53 AM
原帖由 无我不在 于 2009-1-23 11:01 PM 发表
应用: 2D Array in password setting with display '*' sign. (.c language only)

状况:通常在网路申请新户口时,官方会要求设定密码,同时要求输入多一回以确定你的密码。如果不相同,系统要求重新输入。 ...




看你的判斷一下是文字, 一下是數字, 你確定你的程式可以編譯??
作者: 无我不在    时间: 2009-1-24 07:20 AM
标题: 回复 #53 Super-Tomato 的帖子
这个是我sub out的小编,和之前的作业没关系的。

我在之前 1D char 的 * 号效果可以完美运行的。*号的结构没问题的。
作者: 无我不在    时间: 2009-1-24 07:38 AM
如果加一个for loop给p,就没有*好的效果了。
作者: Super-Tomato    时间: 2009-1-24 05:25 PM
原帖由 无我不在 于 2009-1-24 07:20 AM 发表
这个是我sub out的小编,和之前的作业没关系的。

我在之前 1D char 的 * 号效果可以完美运行的。*号的结构没问题的。



不是说之前的,而是这段

                                                if(letter==8)   
                                                {   
                                                        password[p][--i]=NULL;   
                                                        putchar(8);   
                                                        putchar('   ');   
                                                        putchar(8);   
                                                }
                                                else
                                                {
                                                        if(letter!="\r")
                                                        {
                                                                password[p][i++]=letter;
                                                                putchar('*');
                                                        }
                                                }

letter 已经定义为 char 但是判断的时候怎么会是和数字做比較??
再来就是 password_check 的定义不是多余的吗?
作者: goodhermit95    时间: 2009-1-24 05:50 PM
借问下,C/C++ 和 C# 的概念完全不同?
作者: Super-Tomato    时间: 2009-1-24 06:14 PM
原帖由 goodhermit95 于 2009-1-24 05:50 PM 发表
借问下,C/C++ 和 C# 的概念完全不同?



虽然没直接使用过 C#, 但以我看过的 coding 来说,C#的结构偏向 JAVA, 呈现方式偏向 C
作者: goodhermit95    时间: 2009-1-24 06:23 PM
标题: 回复 #58 Super-Tomato 的帖子
em0010
C++ 好像没有streamreader,my.application.restart 之类的东西
作者: 无我不在    时间: 2009-1-24 10:02 PM
原帖由 Super-Tomato 于 2009-1-24 05:25 PM 发表



不是说之前的,而是这段

                                                if(letter==8)   
                                                {   
                                            ...

这段一定能运行的。
char也能解读数字的。
作者: Jay1515Jay    时间: 2009-1-24 11:42 PM
原帖由 Super-Tomato 于 2009-1-24 06:14 PM 发表



虽然没直接使用过 C#, 但以我看过的 coding 来说,C#的结构偏向 JAVA, 呈现方式偏向 C

C#是C family的J#?em0007
名字都很像




欢迎光临 JBTALKS.CC (https://www.jbtalks.cc/) Powered by Discuz! X2.5