提问:为什么第一次输出please input a double:后,输入一个数后,没有显示do you want to input again:而且answe
这段代码错哪了?为什么输出的不对?#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
typedef struct B{
double array[5];
struct B* next;
}A;
int main(void)
{
A* current =NULL;
A* top=NULL;
A* before=NULL;
char answer='y';
double sum=0.0;
int i=0;
for(;;){
current=(A*)malloc(sizeof(A));
for( i=0;i<5;i++){
printf("please input a double:");
scanf("%lf",&(current->array[i]));
printf("do you want to input again:");
scanf("%c",&answer);
if(tolower(answer)=='n')
break;
}
if(top==NULL){
top=current;
before=current;
before->next=NULL;
}else
{ before->next=current;
current->next=NULL;
}
if(tolower(answer)=='n')
break;
}
current=top;
while(current!=NULL){
while(current->array[ i++]!='\0')
sum+=current->array[i];
current=current->next;
}
printf("%lf",sum);
return 0;
}