我是C编程的新手,所以我试图让用户使用switch语句计算某些东西,问题是结果没有显示在程序上,例如,如果我输入1并输入50 * 6.63,结果为空。
#include <stdio.h>
#include <stdlib.h>
int main()
{
float Str;
float bonusArmor;
float Haste;
float Crit;
float Multi;
float Vera;
float Mas;
float result;
int option;
printf("Press 1 for Strength\n");
printf("Press 2 for Bonus Armor\n");
printf("Press 3 for Haste\n");
printf("Press 4 for Critical Strike\n");
printf("Press 5 for Multistrike\n");
printf("Press 6 for Versaility\n");
printf("Press 7 for Mastery\n");
scanf("%d", &option);
switch(option){
case 1:
printf("Enter Strength:\n");
scanf("%f", &Str);
result = (6.63*Str);
printf("Total is: ", result);
break;
case 2:
printf("Enter Bonus Armor:\n");
scanf("%f", &bonusArmor);
result = 6.30*bonusArmor;
printf("Total is: ", result);
break;
case 3:
printf("Enter Haste:\n");
scanf("%f", &Haste);
result = 3.66*Haste;
printf("Total is: ", result);
break;
case 4:
printf("Enter Critical Strike:\n");
scanf("%f", &Str);
result = 3.57*Str;
printf("Total is: ", result);
break;
case 5:
printf("Enter Multistrike:\n");
scanf("%f", &Str);
result = 3.18*Str;
printf("Total is: ", result);
break;
case 6:
printf("Enter Versatility:\n");
scanf("%f", &Vera);
result = 2.63*Vera;
printf("Total is: ", result);
break;
case 7:
printf("Enter Mastery:\n");
scanf("%f", &Mas);
result = 2.49*Mas;
printf("Total is: ", result);
break;
default:
printf ("Invalid input");
}
return 0;
}
答案 0 :(得分:0)
答案 1 :(得分:0)
您必须指定转换规范才能打印值:
printf("float: %f\n", floatValue);
换行符可确保您在打印时显示输出。
#include <stdio.h>
#include <stdlib.h>
int main()
{
float Str;
float bonusArmor;
float Haste;
float Crit;
float Multi;
float Vera;
float Mas;
float result;
int option = 0;
printf("Press 1 for Strength\n");
printf("Press 2 for Bonus Armor\n");
printf("Press 3 for Haste\n");
printf("Press 4 for Critical Strike\n");
printf("Press 5 for Multistrike\n");
printf("Press 6 for Versatility\n");
printf("Press 7 for Mastery\n");
scanf("%d", &option);
switch(option){
case 1:
printf("Enter Strength:\n");
scanf("%f", &Str);
result = (6.63*Str);
printf("Total is: %f\n", result);
break;
case 2:
printf("Enter Bonus Armor:\n");
scanf("%f", &bonusArmor);
result = 6.30*bonusArmor;
printf("Total is: %f\n", result);
break;
case 3:
printf("Enter Haste:\n");
scanf("%f", &Haste);
result = 3.66*Haste;
printf("Total is: %f\n", result);
break;
case 4:
printf("Enter Critical Strike:\n");
scanf("%f", &Str);
result = 3.57*Str;
printf("Total is: %f\n", result);
break;
case 5:
printf("Enter Multistrike:\n");
scanf("%f", &Str);
result = 3.18*Str;
printf("Total is: %f\n", result);
break;
case 6:
printf("Enter Versatility:\n");
scanf("%f", &Vera);
result = 2.63*Vera;
printf("Total is: %f\n", result);
break;
case 7:
printf("Enter Mastery:\n");
scanf("%f", &Mas);
result = 2.49*Mas;
printf("Total is: %f\n", result);
break;
default:
printf("Invalid input\n");
break;
}
return 0;
}