| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 679 人关注过本帖
标题:提问:为什么第一次输出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: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册: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
快速回复:提问:为什么第一次输出please input a double:后,输入一个数后,没有 ...
数据加载中...
 
   



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

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