我从下面的程序中得到了我想要的错误消息,但我不知道为什么 在 dev c++ 中使用 c 编程

问题描述

This is an image example of the problem.

下面的代码是我的 ICT 老师给我的作业。我的客人说这个错误的原因是因为我的if-else语句在我输入错误的字母类时运行了两次,但我不知道如何解决

#include <stdio.h>
#include <ctype.h>
int main ()
{
float rate,distance,claim; 
char class;

printf("......................................................\n");
printf("\t\t\t Class of Vehicle\n");
printf("......................................................\n");
printf("\t\t\t  A   B   C   D\n");
printf("\tRate  (cent/km)\t  70  60  50  45\n");    
printf("......................................................\n\n");

label1:
    printf("Enter Class of Vehicle\t\t: ");
    scanf("%c",&class);
    class = toupper(class);

if (class == 'A')
{
    rate = 70;
}
    else if (class == 'B')
    {
        rate = 60;
    }
        else if (class == 'C')
        {
            rate = 50;
        }
            else if (class == 'D')
            {
                rate = 45;
            }
                else
                {
                    printf("Invalid input. Please start again.\n");
                    goto label1;
                }

label2: 
printf("Enter distance Travelled (km)\t: ");
scanf("%f",&distance);

if (distance < 0 )
{
    printf("Invalid input. Please start again.\n");
    goto label2;
}

claim = rate / 100 * distance;

printf("Amount of Claim (RM)\t\t: %.2f",claim);

return 0;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)