| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 365 人关注过本帖
标题:C语言while语句问题
只看楼主 加入收藏
我是含羞草
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2015-5-18
结帖率:60%
收藏
已结贴  问题点数:10 回复次数:1 
C语言while语句问题
用700元购入物品的程序,执行后得到


Line up;
1:notebook \150
2:mechanical pencil \180
3:highlight marker set \210
4:eraser \110
Now You have \700 now. What do you want?
Input number of items:1
You've got a notebook.
Now You have \550 now. What do you want?
Input number of items:2
You've got a mechanical pencil.
Now You have \370 now. What do you want?
Input number of items:3
You've got highlight marker set.
Now You have \160 now. What do you want?
Input number of items:4
You've got a eraser.

Total items : 4
Remaining money : 50





Line up;
1:notebook \150
2:mechanical pencil \180
3:highlight marker set \210
4:eraser \110
Now You have \700 now. What do you want?
Input number of items:0
Error! Choose number 1-4 .
Now You have \700 now. What do you want?
Input number of items:1
You've got a notebook.
Now You have \550 now. What do you want?
Input number of items:1
You've got a notebook.
Now You have \400 now. What do you want?
Input number of items:1
You've got a notebook.
Now You have \250 now. What do you want?
Input number of items:1
You've got a notebook.

Total items : 4
Remaining money : 100.

[ 本帖最后由 我是含羞草 于 2015-5-21 16:27 编辑 ]
搜索更多相关主题的帖子: C语言 number notebook mechanical 
2015-05-21 16:26
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:10 
#include<stdio.h>
int min(int a,int b,int c,int d){
    return a>b?b:a>c>d?d:c?c>d?d:c:a>b?b:a;
}
main(){
    printf("Line up;\n");
    printf("1:notebook \\150\n");
    printf("2:mechanical pencil \\180\n");
    printf("3:highlight marker set \\210\n");
    printf("4:eraser \\110\n");
    int ch,sum=700,count=0;  
    while(sum>min(110,210,280,150)){
        printf("Now You have \\%d now. What do you want?\n\nInput number of items:",sum);
        scanf("%d",&ch);
        switch(ch){
            case 1:sum-=150;printf("You've got a notebook.\n");break;
            case 2:sum-=180;printf("You've got a mechanical pencil.\n");break;
            case 3:sum-=210;printf("You've got highlight marker set.\n");break;
            case 4:sum-=110;printf("You've got a eraser.\n");
        }
        count++;
    }
    printf("\n\nTotal items : %d\n",count);
    printf("Remaining money : %d",sum);
}

剑栈风樯各苦辛,别时冰雪到时春
2015-05-21 17:05
快速回复:C语言while语句问题
数据加载中...
 
   



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

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