Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.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 - Fatal编程技术网

C程序以字符串形式计算用户输入,并将总成本打印成整数

C程序以字符串形式计算用户输入,并将总成本打印成整数,c,C,有人能帮我理解这个问题并给出答案吗?我一整天都在想这个问题 马克·丹尼尔斯是一位木匠,他创造了个性化的房屋标志。他希望应用程序根据以下因素计算任何sign a客户订单的价格: *所有标志的最低费用为30美元。 *如果标志是橡木做的,加15美元。松树不收费。 *前六个字母或数字包含在最低费用中;每增加一个角色要收费3美元。 *最低费用包括黑色或白色字符;金叶字体另收费12美元。 向用户询问以下信息: 1) 他们的标志是橡树(O)还是松树(P) 2) 他们的符号是多少个字母或字符 3) 他们想要金色

有人能帮我理解这个问题并给出答案吗?我一整天都在想这个问题

马克·丹尼尔斯是一位木匠,他创造了个性化的房屋标志。他希望应用程序根据以下因素计算任何sign a客户订单的价格: *所有标志的最低费用为30美元。 *如果标志是橡木做的,加15美元。松树不收费。 *前六个字母或数字包含在最低费用中;每增加一个角色要收费3美元。 *最低费用包括黑色或白色字符;金叶字体另收费12美元。 向用户询问以下信息: 1) 他们的标志是橡树(O)还是松树(P) 2) 他们的符号是多少个字母或字符 3) 他们想要金色(G)还是普通(N)字体 然后打印出他们招牌的费用

 #include <stdio.h>
    #include <stdlib.h>
    #include <stdint.h>>

    int main()
    {
        const int MIN_CHARGE = 30;
        const int OAK_CHARGE = 15;
        const int PINE_CHARGE = 0;
        char woodType;
        int lettercount;
        const int ADDITION_CHAR;
        char textType;
        const int GOLD_LEAF = 12;
        int totalCost;



        printf("Type 'O' for Oak and 'P' for Pine: ");
        scanf_s("%c",&woodType, 1);
            if (woodType = 'O')
            {
                totalCost = MIN_CHARGE + OAK_CHARGE;
                printf("The total cost of oak is: %d", &wood);
            }
            else
        {
            totalCost = MIN_CHARGE;
            printf("The total cost of pine is: %d\n", totalCost);
        }

        printf("How many letters or numbers are in your sign? ");
        scanf_s("%d", &lettercount);

            if (lettercount > 6)
            {
                totalCost = totalCost + ADDITION_CHAR * (lettercount - 6);
                printf("The total cost of letters is: %d", totalCost);
            }

        else
        {
            printf("Type 'G' for Gold and 'N' for normal letters \n");
            scanf_s("%c", &textType, 1);

        }
            if (textType == 'G' || textType == 'g')
            {
                totalCost = totalCost + GOLD_LEAF;
                printf("The total cost of gold leaf letters is: %d\n", totalCost);
            }


        printf("The total cost of sign is: %d\n", totalCost);

        return 0;
    }`
#包括
#包括
#包括>
int main()
{
最小电荷常数=30;
费用=15;
成本成本=0;
木炭型;
整数字母计数;
const int ADDITION_CHAR;
字符文本类型;
const int GOLD_LEAF=12;
总成本;
printf(“橡树输入‘O’,松树输入‘P’”);
scanf_s(“%c”和woodType,1);
如果(woodType='O')
{
总成本=最低费用+橡木费用;
printf(“橡木的总成本为:%d”&木材);
}
其他的
{
总成本=最低费用;
printf(“pine的总成本为:%d\n”,总成本);
}
printf(“你的标志中有多少字母或数字?”);
扫描单位(“%d”和字母计数);
如果(信数>6)
{
totalCost=totalCost+加法字符*(字母计数-6);
printf(“信件的总成本为:%d”,总成本);
}
其他的
{
printf(“键入'G'表示金色,键入'N'表示普通字母\N”);
scanf_s(“%c”和文本类型,1);
}
如果(textType='G'| | textType=='G')
{
总成本=总成本+金叶;
printf(“金叶字母的总成本为:%d\n”,总成本);
}
printf(“签名的总成本为:%d\n”,总成本);
返回0;
}`

理查德。我希望你做得很好

  • 问题不在于输入值后通知总成本。如果我是你,我不会这么做。让事情变得简单,只做问题想做的事

    printf(“橡木的总成本为:%d”,&wood)在这一行中,您忘记声明de变量'wood'

  • 在这里,你的代码是完全错误的

    if(信数>6)
    {
    totalCost=totalCost+加法字符*(字母计数-6);
    printf(“信件的总成本为:%d”,总成本);
    }否则{
    printf(“键入'G'表示金色,键入'N'表示普通字母\N”);
    scanf_s(“%c”和文本类型,1);
    }

    你们在这里做错的事和“其他”有关。在这里,如果他需要超过6个字母,程序不会让用户说他想要黄金还是普通字母

  • 最后,这里必须在“%c”前面加一个空格。这可能看起来很奇怪,但要知道为什么必须在“%c”之前使用空格,您需要知道什么是缓冲区。你可以更多地了解他们

    printf(“键入'G'表示金色,键入'N'表示普通字母\N”);
    scanf_s(“%c”和文本类型,1)

  • 总的来说,您的代码需要更多的关注。尝试使用更少的变量可以帮助你很多,特别是在微控制器方面(我不知道这是否是你的目标)。此外,您可以检查我自己的分辨率:

    #include <stdio.h>
    #include <stdlib.h>
    #include <stdint.h>>
    
    int main(){
            const int OAK_CHARGE   = 15;
            const int GOLD_LEAF    = 12;
            const int ADDITION_CHAR = 3;
            char woodType, textType;
            int lettercount = 0;
            int totalCost = 30;
    
            printf("Type 'O' for Oak or 'P' for Pine: ");
            scanf_s(" %c",&woodType, 1);
            if (woodType == 'O' || woodType == 'o'){
                totalCost += OAK_CHARGE;
            }
    
            printf("How many letters or numbers are in your sign? ");
            scanf_s("%d", &lettercount);
            if (lettercount > 6){
                totalCost += ADDITION_CHAR*(lettercount - 6);
            }
    
            printf("Type 'G' for Gold and 'N' for normal letters: ");
            scanf_s(" %c",&textType, 1);
            if (textType == 'G' || textType == 'g'){
                totalCost += GOLD_LEAF;
            }
    
            printf("The total cost of sign is: %d", totalCost);
            return 0;
        }
    
    #包括
    #包括
    #包括>
    int main(){
    费用=15;
    const int GOLD_LEAF=12;
    常量int加法_CHAR=3;
    字符类型,文本类型;
    int-lettCount=0;
    总成本=30;
    printf(“橡树的“O”型或松树的“P”型:”);
    scanf_s(“%c”和woodType,1);
    如果(woodType='O'| | woodType=='O'){
    总成本+=橡木桶费用;
    }
    printf(“你的标志中有多少字母或数字?”);
    扫描单位(“%d”和字母计数);
    如果(信数>6){
    总成本+=添加字符*(字母计数-6);
    }
    printf(“输入'G'表示金色,输入'N'表示普通字母:”);
    scanf_s(“%c”和文本类型,1);
    如果(textType='G'| | textType=='G'){
    总成本+=金叶;
    }
    printf(“符号的总成本为:%d”,总成本);
    返回0;
    }
    
    请注意,可能存在更好的解决方案。每个人都有自己的编码风格。
    嗯,我希望我能帮上忙

    我一直收到这些错误警告C4477'printf:“格式字符串'%d'需要'int'类型的参数,但变量参数1的类型为'int*'警告C4700未初始化的局部变量'ADDITION_CHAR''printf(“橡木的总成本为:%d',&wood);”。。。。什么是“&wood”?首先修复这些错误。例如,加法字符1有一个明确的原因:它没有值。加法字符应该是当lettercount大于6时,每个数字加3,你如何分配该值?我想看看是否应该将OAK和PINE CHARGE组合成一个变量。