#include <stdio.h>
int main(void) {
int option;
int many;
char name;
float CNP = 20.00;
float TWS = 30.00;
float FG = 40.00;
float Many1 = 0.00;
float Many2 = 5.00;
float Many3 = 15.00;
while(1){
printf("-------------Welcome-------------\n");
printf("**********M.A.C PETS SPA*********\n");
printf(" choose from our Specials\n");
printf("---------------------------------\n");
printf("[1] CLEAN UP Special includes General shower and haircut - $20.00\n");
printf("-----------------------------------------------------\n");
printf("[2] THE WORKS Special includes General shower, haircut, ear cleaning, and nail trim - $30.00\n");
printf("-----------------------------------------------------\n");
printf("[3] FULL GROOM Special includes Breed appropriate shower, specific haircut, nail trim, ear cleaning, bandana and cologne - $40.00\n");
printf("-----------------------------------------------------\n");
printf("Enter your special: number:\n");
scanf("%d",&option);
if(option == 1)
{
printf("What size is your dog?: ");
printf("[1]: small\n");
printf("[2]: medium\n");
printf("[3]: Large\n");
scanf("%d\n",&many);
printf("Total Price including extra charge for the size is = $%.2f\n",(CNP+many) );
break;
}
else if(option == 2)
{
printf("What size is your dog?: \n");
printf("[1]: small\n");
printf("[2]: medium\n");
printf("[3]: Large\n");
scanf("%d",&many);
printf("Total Price including extra charge for the size is = $%.2f",TWS*many + (TWS*many*0.07) );
break;
}
else if(option == 3)
{
printf("What size is your dog?: \n");
printf("[1]: small\n");
printf("[2]: medium\n");
printf("[3]: Large\n");
scanf("%d",&many);
printf("Total Price including extra charge for the size is = $%.2f",FG*many + (FG*many*0.07) );
break;
}
else printf("Invalid item number! Re-enter item number\n");
}
return 0;
}
我试图给予用户选择他们的狗的大小,并根据他们选择的大小添加额外的费用。我似乎不能得到它的权利,我觉得我需要创建另一个循环或使用struct我需要帮助,请!!
我尝试使用循环和输入让我们说,将是他们选择第一个选项,大小将是中等
则输出将为20.00加上15.00 = 35.00
1条答案
按热度按时间k4ymrczo1#
您不希望
scanf()
字符串包含换行符。已重构以减少代码重复(当您澄清公式时,我将修改我的答案):和运行示例: