标题:提问:为什么第一次输出please input a double:后,输入一个数后,没有显示 ...
只看楼主
郑李孔明
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-4-14
结帖率:0
已结贴  问题点数:20 回复次数:2 
提问:为什么第一次输出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;
}
搜索更多相关主题的帖子: current include please double before 
2014-04-14 14:15
wp231957
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册:2012-10-18
得分:10 
首先 请清除输入缓存  例如

程序代码:
   printf("please input a double:");
   scanf("%lf",&(current->array[i]));
   getchar();
   printf("do you want to input again:");
   scanf("%c",&answer);

DO IT YOURSELF !
2014-04-14 14:40
Andrew_Lee
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:3
帖 子:185
专家分:626
注 册:2014-3-21
得分:10 
我直接复制你的代码,显示了do you want to input again:的啊
2014-04-14 16:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-430078-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040174 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved