| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1316 人关注过本帖
标题:跳过程序语句
只看楼主 加入收藏
RecluseF
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2020-9-10
结帖率:66.67%
收藏
已结贴  问题点数:20 回复次数:4 
跳过程序语句
大佬们,为什么我这个程序在输入第一组数据后回车,程序就结束了?就是只执行到getchar前面的那个程序,实在是看不出哪里有问题。开关语句里还有点小问题还没改,不劳大佬查看了。



#include <stdio.h>
#include <stdlib.h>

int main()
{
    {    double rate,capital;
float deposit;
int year;
char a;

    printf("Input rate, year, capital:");
    scanf("%lf,%d,%lf",&rate,&year,&capital);
    getchar();
    printf("Compound interest (Y/N)?" );
    scanf(" %c",&a);
        switch(a){
        case 'Y':
        printf("deposit = %.4f\n",deposit=capital*pow(1+rate,year));
        break;

        case 'N':deposit=capital*(1+rate*year);
         printf("deposit = %.4f\n",deposit=capital*(1+rate*year));
       break;}
 return 0;
}
    return 0;
}
搜索更多相关主题的帖子: year include 语句 跳过 printf 
2020-09-10 11:40
纯蓝之刃
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:76
帖 子:566
专家分:3690
注 册:2019-7-29
收藏
得分:6 
输入的时候各个变量中间要输入英文的逗号

一沙一世界,一花一天堂。无限掌中置,刹那成永恒。
2020-09-10 12:51
RecluseF
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2020-9-10
收藏
得分:0 
回复 2楼 纯蓝之刃
编译器里是英文的,复制过来就这样了
2020-09-10 13:03
自学的数学
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:46
帖 子:967
专家分:4146
注 册:2017-11-15
收藏
得分:6 
输入状态用英文输入法就OK。
2020-09-10 20:48
hellobird
Rank: 2
等 级:论坛游民
威 望:3
帖 子:14
专家分:47
注 册:2017-4-17
收藏
得分:8 
程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    double rate,capital;
    float deposit;
    int year;
    char a;

    printf("Input rate, year, capital: ");
    scanf("%lf%d%lf",&rate,&year,&capital);
    //printf("%f\t%d\t%f\n", rate, year, capital);
    getchar();
    printf("Compound interest (Y/N)?: " );
    scanf("%c",&a);
    //printf("%c", a);
    switch(a){
    case 'Y':
        printf("deposit = %.4f\n",deposit=capital*pow(1+rate,year));
        break;

    case 'N':deposit=capital*(1+rate*year);
        printf("deposit = %.4f\n",deposit=capital*(1+rate*year));
        break;}
    return 0;
}

图片附件: 游客没有浏览图片的权限,请 登录注册
2020-09-10 21:20
快速回复:跳过程序语句
数据加载中...
 
   



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

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