注册 登录
编程论坛 C++教室

程序出错了?!

jack333fly 发布于 2010-07-19 10:35, 1006 次点击
#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;
}
11 回复
#2
雅雅2010-07-19 11:04
说具体一些啊
#3
gq1987182010-07-19 12:59
double cost(double price, int turnover)
{
    if (turnover <= THRESHORD)
        return(price + price * low);
    else
        return(price + price * high);
    return;//这里注释掉
}
#4
rainbow12010-07-19 13:03
子函数如果为 void 类型,就不要 return 了。
#5
jack333fly2010-07-19 13:52
回复 2楼 雅雅
就是写一个程序来判定商品价格cost,已知进价price和存放天数turnover,如果小于等于七天的话就加5%,如果大于七天就加10%……
#6
jack333fly2010-07-19 13:53
回复 3楼 gq198718
好像还是不行啊~~~
#7
gq1987182010-07-24 15:18
程序代码:
#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;*/
}
#8
gq1987182010-07-24 15:26
程序代码:
#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;
#9
哥只是传说2010-07-24 16:09
学习了
#10
encounter2010-07-24 17:46
{
    if (turnover <= THRESHORD)
        return(price + price * low);
    else
        return(price + price * high);
    return;
}
这个return地返回个值
#11
encounter2010-07-24 17:47
double类型的
#12
encounter2010-07-24 17:57
low和high的类型得改成float或double
还有{
    if (turnover <= THRESHORD)
        return(price + price * low);
    else
        return(price + price * high);
}这样就可以了

1