| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 584 人关注过本帖
标题:[求助]商品价格统计
只看楼主 加入收藏
rejoice007
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2006-4-21
收藏
 问题点数:0 回复次数:1 
[求助]商品价格统计

题目: 商品价格统计

一 语言与环境

A.实现语言
C
B.环境要求
1 .Turbo C 2.0或者以上版本开发环境
二 要求

请用C语言编写一个程序,完成如下功能;定义一个结构数组,输入4种商品的名称,单价,数量,要求计算并逐个输出每种商品的总价,最后输出单价最高的商品价格。
三 实现步骤

1. 定义一个结构体,其中包括商品名称,单价,数量和总价四个成员。
2. 在程序中,使用循环结构控制连续输入(第一个循环)。
2.1 在循环结构中,显示提示信息,要求用户输入商品的名称,单价和数量。
2.2 读取输入的数据
2.3 计算商品总价
3 .在程序中,使用循环结构控制连续输出(第二个循环)。
3.1 循环输出每种商品的总价
3.2 判断并输出单价最高的商品价格
4 .运行结果如下图:
Please enter the name,price and amount of the NO.1 commodity: aaa 1 1
Please enter the name,price and amount of the NO.2 commodity: bbb 2 2
Please enter the name,price and amount of the NO.3 commodity: ccc 3 3
Please enter the name,price and amount of the NO.4 commodity: ddd 4 4
The total prices of aaa is :1The total prices of bbb is :4
The total prices of ccc is :9
The total prices of ddd is :16
The highest price is :4
D:\turboc>




搜索更多相关主题的帖子: 商品 价格 统计 
2006-07-18 09:40
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 

#include<stdio.h>
#define N 4
typedef struct list{
char name[20];
int price;
int amount;
int sum;
}Goods;

int main()
{
Goods data[N];
int max=0,i=0;
while(i<N)
{
printf("Please enter the name,price and amount of the NO.%d commodity:",i+1);
scanf("%s%d%d",data[i].name,&data[i].price,&data[i].amount);
i++;
}
i=0;
while(i<N)
{
data[i].sum=data[i].price*data[i].amount;
if(max<data[i].price)
max=data[i].price;
//printf("%d %d ",data[i].price,data[i].amount);
printf("The total prices of %s is :%d\n",data[i].name,data[i].sum);
i++;
}
printf("The highest price is :%d\n",max);
return(0);
}


倚天照海花无数,流水高山心自知。
2006-07-18 19:48
快速回复:[求助]商品价格统计
数据加载中...
 
   



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

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