| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1006 人关注过本帖
标题:程序出错了?!
只看楼主 加入收藏
jack333fly
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2010-7-15
结帖率:83.33%
收藏
已结贴  问题点数:5 回复次数:11 
程序出错了?!
#include <iostream>
using namespace std;
void get(double& price, int& turnover);
double cost(double price, int turnover);
void show_output(double price, int turnover, double cost);
const int THRESHORD = 7;
const int low = 0.05;
const int high = 0.10;
int main()
{
    double cost1, price;
    int turnover;
    get(price, turnover);
    cost1 = cost(price, turnover);
    show_output(price, turnover, cost1);
    return 0;
}
void get(double& price, int& turnover)
{
    cout << "Please enter price and turnover:" << endl;
    cin >> price >> turnover;
    return;
}
double cost(double price, int turnover)
{
    if (turnover <= THRESHORD)
        return(price + price * low);
    else
        return(price + price * high);
    return;
}
void show_output(double price, int turnover, double cost)
{
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);
    cout << "The cost for price " << price << endl
         << "and turnover " << turnover << endl
         << "is:" << cost << endl;
    return;
}
搜索更多相关主题的帖子: void include double return price 
2010-07-19 10:35
雅雅
Rank: 2
等 级:论坛游民
帖 子:38
专家分:34
注 册:2010-7-4
收藏
得分:1 
说具体一些啊
2010-07-19 11:04
gq198718
Rank: 4
等 级:业余侠客
威 望:1
帖 子:86
专家分:200
注 册:2010-6-6
收藏
得分:1 
double cost(double price, int turnover)
{
    if (turnover <= THRESHORD)
        return(price + price * low);
    else
        return(price + price * high);
    return;//这里注释掉
}
2010-07-19 12:59
rainbow1
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:2
帖 子:277
专家分:839
注 册:2010-5-19
收藏
得分:1 
子函数如果为 void 类型,就不要 return 了。
2010-07-19 13:03
jack333fly
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2010-7-15
收藏
得分:0 
回复 2楼 雅雅
就是写一个程序来判定商品价格cost,已知进价price和存放天数turnover,如果小于等于七天的话就加5%,如果大于七天就加10%……
2010-07-19 13:52
jack333fly
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2010-7-15
收藏
得分:0 
回复 3楼 gq198718
好像还是不行啊~~~
2010-07-19 13:53
gq198718
Rank: 4
等 级:业余侠客
威 望:1
帖 子:86
专家分:200
注 册:2010-6-6
收藏
得分:0 
程序代码:
#include <iostream>
using namespace std;
void get(double& price, int& turnover);
double cost(double price, int turnover);
void show_output(double price, int turnover, double cost);
const int THRESHORD = 7;
const int low = 0.05;
const int high = 0.10;
void main()
{
    double cost1, price;
    int turnover;
    get(price, turnover);
    cost1 = cost(price, turnover);
    show_output(price, turnover, cost1);
    getchar();
}
void get(double& price, int& turnover)
{
    cout << "Please enter price and turnover:" << endl;
    cin >> price >> turnover;
   /* return;*/
}
double cost(double price, int turnover)
{
    if (turnover <= THRESHORD)
        return(price + price * low);
    else
        return(price + price * high);
    /*return ;*/
}
void show_output(double price, int turnover, double cost)
{
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);
    cout << "The cost for price " << price << endl
         << "and turnover " << turnover << endl
         << "is:" << cost << endl;
    /*return;*/
}
2010-07-24 15:18
gq198718
Rank: 4
等 级:业余侠客
威 望:1
帖 子:86
专家分:200
注 册:2010-6-6
收藏
得分:0 
程序代码:
#include <iostream>
using namespace std;
void get(double& price, int& turnover);
double cost(double price, int turnover);
void show_output(double price, int turnover, double cost);
const int THRESHORD = 7;
const double low = 0.05;
const double high = 0.10;
void main()
{
    double cost1, price;
    int turnover;
    get(price, turnover);
    cost1 = cost(price, turnover);
    show_output(price, turnover, cost1);
    getchar();
}
void get(double& price, int& turnover)
{
    cout << "Please enter price and turnover:" << endl;
    cin >> price >> turnover;
   /* return;*/
}
double cost(double price, int turnover)
{
    if (turnover <= THRESHORD)
        return(price + price * low);
    else
        return(price + price * high);
    /*return ;*/
}
void show_output(double price, int turnover, double cost)
{
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);
    cout << "The cost for price " << price << endl
         << "and turnover " << turnover << endl
         << "is:" << cost << endl;
    /*return;*/
}
那个const int low = 0.05;
const int high = 0.10;  以意味着 low=0,high=0了,
要换成const double low = 0.05;
const double high = 0.10;
2010-07-24 15:26
哥只是传说
Rank: 2
等 级:论坛游民
帖 子:27
专家分:22
注 册:2010-7-18
收藏
得分:1 
学习了
2010-07-24 16:09
encounter
Rank: 5Rank: 5
来 自:扬州
等 级:职业侠客
威 望:2
帖 子:150
专家分:359
注 册:2010-7-24
收藏
得分:1 
{
    if (turnover <= THRESHORD)
        return(price + price * low);
    else
        return(price + price * high);
    return;
}
这个return地返回个值

ping   nbtstat   netstat   tracert    nat   at    ftp   telnet..................
2010-07-24 17:46
快速回复:程序出错了?!
数据加载中...
 
   



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

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