Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 如何生成如下所示的输出?_C_Dynamic Programming_Clang++_Llvm Clang - Fatal编程技术网

C 如何生成如下所示的输出?

C 如何生成如下所示的输出?,c,dynamic-programming,clang++,llvm-clang,C,Dynamic Programming,Clang++,Llvm Clang,我已经写了下面的代码。它首先检查用户的输入,但如果条件为false,它不会再次询问“输入员工的号码代码(1,2,3,4,5)” 如何生成如下图所示的输出 #包括 #包括 #包括 #包括 内部主(空) { 字符码; printf(“\n输入员工编号代码(1,2,3,4,5):”; scanf(“%c”、&code); //检查用户输入的字符是否为字母 if(isalpha(代码)==0) { //printf(“%c是一个数字。\n”,代码); int x=code-'0';//将alpha字

我已经写了下面的代码。它首先检查用户的输入,但如果条件为false,它不会再次询问“输入员工的号码代码(1,2,3,4,5)”

如何生成如下图所示的输出

#包括
#包括
#包括
#包括
内部主(空)
{ 
字符码;
printf(“\n输入员工编号代码(1,2,3,4,5):”;
scanf(“%c”、&code);
//检查用户输入的字符是否为字母
if(isalpha(代码)==0)
{
//printf(“%c是一个数字。\n”,代码);
int x=code-'0';//将alpha字符转换为数字
乐趣(x);
//printf(“%d是一个数字。\n”,x);
}
其他的
printf(“无法识别的工资代码。请仅为经理输入'1',每小时输入'2',佣金输入'3',计件工输入'4'或'\n');
返回0;
}
void fun(int代码)
{ 
浮动总数=0;
浮动工资、销售、工时、工资、小时总计、通讯总计、个人总计;
浮动项目a、项目b、项目c;
浮动项目1、项目2、项目3;
字符s;
while(代码!=-1)
{
开关(代码)
{
案例1:
printf(“输入经理的工资代码:”);
scanf(“%f”、&pay);
printf(“经理工资:$%.2f\n\n”,工资);
总额+=工资;
薪金=总额;
打破
案例2:
printf(“输入小时工工资率:”);
scanf(“%f”、&pay);
printf(“输入工作小时数:”);
scanf(“%f”、&hours);
如果(小时数>40)
工资=(工资*40)+(小时数-40)*(工资*1.5));
其他的
工资=工资*小时;
printf(“工资为:$%.2f\t\n\n”,工资,工资);
总额+=工资;
hourlyTotal=工资;
打破
案例3:
printf(“输入佣金员工的销售总额:”);
scanf(“%f”和项目a);
项目a=项目a*.057;
printf(“输入佣金员工的销售总额:”);
scanf(“%f”和项目b);
项目b=项目b*.064;
printf(“输入佣金员工的毛项目销售额:”);
scanf(“%f”和项目c);
项目c=项目c*.072;
销售=a项+b项+c项;
支付=250+销售;

printf(“通信工资为:$%.2f不检查输入是否为int。 然后,在switch中,do:(注意字符的引号)

开关“1”:
开关'a':/*或任何您想要使用lke 1的字符输入*/
/*做事*/
中断;/*重要*/
开关“2”:

/*继续*/
这段代码很难理解。你能给你的函数起个有意义的名字吗?“有趣“不完全是不言自明的。您还需要将其分解为更小、更容易理解的组件。您不应将屏幕截图链接为文本,而应将预期和实际输出显示为文本。是的,但对我的激励作用很小。没有任何错误会导致您无法获得另一个“输入员工编号代码”提示。我能看到的唯一错误是在“scanf(“%cf”、&item_3)”行中,它应该是“%f”。您有一个逻辑错误,在第一次之后,您没有验证输入的员工编号是否是一个数字。在fun()中进行提示并在循环中获取信息比两次更好。
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
 #include <stdlib.h>

int main (void)
{ 

char  code;


    printf ("\nEnter employee's number code (1,2,3,4,5): ");
    scanf ("%c", &code);

 //Check whether a Character Entered by User is Alphabet or not

if (isalpha(code) == 0)
    {
    //printf("%c is an number.\n", code);
    int x = code - '0'; // convert alpha char to number
    fun(x);
    //printf("%d is an number.\n", x);
    }
else
     printf( "Unrecognised paycode. Please only enter  '1' for manager, '2' hourly, '3'  commission, '4' Pieceworker or '' \n");

return 0;
  }

void fun(int code) 
   { 
         float total = 0;
       float pay, sales, hours, salary, hourlyTotal, comm_total, pice_total;
     float item_a, item_b, item_c;
     float item_1, item_2, item_3;
    char s;

while (code != -1)
{

    switch (code)
    {
        case 1:  

            printf ("Enter the manager's paycode: ");
            scanf ("%f", &pay);


            printf ("Manager salary of:$%.2f\n\n", pay);


            total += pay;

            salary = total;
            break;

        case 2: 
            printf ("Enter hourly worker's pay rate: ");
            scanf ("%f", &pay);


            printf ("Enter the number of hours worked: ");
            scanf ("%f", &hours);


            if (hours > 40)
                pay = (pay * 40) + ((hours - 40) * (pay * 1.5));
            else
                pay = pay * hours;


            printf ("Wages are :$%.2f  \t <$%.2f regular and $0.00 overtime> \n\n", pay, pay);


            total += pay;

    hourlyTotal = pay;

            break;

        case 3: 
            printf ("Enter commission employee's gross item_a sales: ");
            scanf ("%f", &item_a);
            item_a = item_a * .057;

            printf ("Enter commission employee's gross item_b sales: ");
            scanf ("%f", &item_b);
            item_b = item_b * .064;


            printf ("Enter commission employee's gross item_c sales: ");
            scanf ("%f", &item_c);
            item_c = item_c * .072;


            sales = item_a +item_b+item_c;


            pay = 250 + sales;


            printf ("Commsion wage is:$%.2f  <$250.00 base + $%.2f commission <$%.2f item A, $%.2f item B, $%.2f item C> \n\n", pay, sales, item_a, item_b, item_c);


            total += pay;

    comm_total = pay;

            break;

        case 4: 
            printf ("\nEnter the number of item_1 completed: ");
            scanf ("%f", &item_1);
            item_1 = item_1*22.50;

            printf ("\nEnter the number of item_2 completed: ");
            scanf ("%f", &item_2);
            item_2 = item_2*24.50;



            printf ("\nEnter the number of item_3 completed: ");
            scanf("%cf", &item_3);
            //if (isdigit(s)) 
            //printf("%c number \n", s);
                //item_3 = s;
            item_3 = item_3*26.00;





            pay = item_1 + item_2 + item_3;


            printf ("Pieceworker wage is:$%.2f <item_1 $%.2f, item_2 $%.2f, item_3 $%.2f> \n\n", pay,item_1, item_2,item_3);


            total += pay;

    pice_total = pay;

            break;

  case 5: 
            printf ("\n Manager: Employees : 1 Total wages:$%.2f ", salary);
    printf ("\n Hourly: Employees : 1 Total wages:$%.2f ", hourlyTotal);
    printf ("\n Commission: Employees : 1 Total wages:$%.2f ", comm_total);
    printf ("\n Pieceworker: Employees : 1 Total wages:$%.2f ", pice_total);
    printf ("\n Net Total: Employees : 4 Total wages:$%.2f ", total);

            break;

        default: 
            printf ("You have entered an invalid code.\n");
    }


    printf ("\nEnter employee's number code (1,2,3,4,5): ");
    scanf ("%d", &code);
}


printf ("\nThe total payroll for the week is: %.2f\n", total);
  }