【发布时间】:2018-01-27 20:15:09
【问题描述】:
有人可以帮忙告诉我我的代码有什么问题吗?我想问用户他/她朋友的两个名字和他们的年龄。然后返回他们年龄的平均值。但输出不如预期。
#include <stdio.h>
int main(void){
char friend1;
char friend2;
float age1;
float age2;
float average;
printf("Please enter name of your friend...\n");
scanf("%s", &friend1);
printf("How old is %s?\n",&friend1);
scanf("%f", &age1);
printf("Enter name of one more friend!\n");
scanf("%s",&friend2);
printf("How old is %s?\n", &friend2);
scanf("%f", &age2);
average = (age1+age2)/2;
printf("Average age of your friends %s and %s is %4.2f years old\n" ,&friend1,&friend2,&average);
return 0;
}
【问题讨论】:
-
那输出是什么?