C++ 处理函数和返回值问题的特殊学校代码

C++ 处理函数和返回值问题的特殊学校代码,c++,function,return,return-value,C++,Function,Return,Return Value,这是我们为我的100级类所处理的一个特殊问题,我们最近在代码中添加了函数。我似乎能够准确地知道如何让代码运行。另外,我的老师说我的变量getSID不需要返回值,这让我有点困惑,非常感谢您的帮助!!多谢各位 #include <iostream> #include <iomanip> using namespace std; //here are the function prototypes for my problem int getSID(int &); i

这是我们为我的100级类所处理的一个特殊问题,我们最近在代码中添加了函数。我似乎能够准确地知道如何让代码运行。另外,我的老师说我的变量getSID不需要返回值,这让我有点困惑,非常感谢您的帮助!!多谢各位

#include <iostream>
#include <iomanip>

using namespace std;
//here are the function prototypes for my problem
int getSID(int &);
int getResidentStatus(int &);
double calculateTuition(double, double, double, double, double, double);
double calculateTax(double &);

int main()
{//declared variables
    char name[20], address[30], veteran, runningStart;
    int credits, SID, residency;
    double tuitionCost, taxDeductible, serviceFee, techFee, facilitiesFee, studentCenterFee, tuitionCostAndFees;

    cout << "***********************************" << endl;
    cout << "*                                 *" << endl;
    cout << "*  Green River Community College  *" << endl;
    cout << "*                                 *" << endl;
    cout << "*        12401 SE 320th St.       *" << endl;
    cout << "*      Auburn, WA, 98092-3622     *" << endl;
    cout << "*                                 *" << endl;
    cout << "*      Phone (253) 833-9111       *" << endl;
    cout << "*                                 *" << endl;
    cout << "***********************************" << endl;

    cout << "Enter name:";
    cin.getline(name, 20);
    getSID(SID);//my teacher says this doesn't need to use a return value?
    getResidentStatus(residency);
    cout << "Are you a veteran(y or n)?:";
    cin >> veteran;
    while (!(veteran == 'y' || veteran == 'n'))
    {
        cout << "Enter either 'y' for yes or 'n' for no: ";
        cin >> veteran;
    }
    cin.ignore();
    cout << "Are you involved in the running start program(y or n)?:";
    cin >> runningStart;
    while (!(runningStart == 'y' || runningStart == 'n'))
    {
        cout << "Enter either 'y' for yes or 'n' for no: ";
        cin >> runningStart;
    }
    cin.ignore();
    cout << "Enter home address(street address, and city):";
    cin.getline(address, 30);
    cout << "Enter number of credits:";
    cin >> credits;
    serviceFee = credits*0.5;
    if (credits <= 12)
    {
        techFee = credits * 5;
    }
    else if (credits>12)
    {
        techFee = 60;
    }
    if (residency == 1 && credits>18)
    {
        tuitionCost = ((credits - 18)*268.26) + (149 * 8) + (278.84 * 10);
    }
    else if (residency == 1 && credits>10)
    {
        tuitionCost = ((credits - 10) * 149) + (278.84 * 10);
    }
    else if (residency == 1 && credits <= 10)
    {
        tuitionCost = (credits*278.84);
    }
    if (residency == 2 && credits>18)
    {
        tuitionCost = ((credits - 18)*109.26) + (53.68 * 8) + (119.84 * 10);
    }
    else if (residency == 2 && credits>10)
    {
        tuitionCost = ((credits - 10)*53.68) + (119.84 * 10);
    }
    else if (residency == 2 && credits <= 10)
    {
        tuitionCost = (credits*119.84);
    }
    if (residency == 3 && credits>18)
    {
        tuitionCost = ((credits - 18)*96.26) + (52.99 * 8) + (106.84 * 10);
    }
    else if (residency == 3 && credits>10)
    {
        tuitionCost = ((credits - 10)*52.99) + (106.84 * 10);
    }
    else if (residency == 3 && credits <= 10)
    {
        tuitionCost = (credits*106.84);
    }
    if (veteran == 'y'&&credits>18)
    {
        tuitionCost = ((credits - 18)*96.26) + (52.99 * 8) + (96.26 * 10);
    }
    else if (veteran == 'y'&&credits>10)
    {
        tuitionCost = ((credits - 10)*52.99) + (96.26 * 10);
    }
    else if (veteran == 'y'&&credits <= 10)
    {
        tuitionCost = (credits*96.26);
    }
    if (runningStart == 'y')
    {
        tuitionCostAndFees = 0;
    }
    if (credits <= 10)
    {
        facilitiesFee = 17.5 + (credits - 5)*3.5;
    }
    else
        facilitiesFee = 35;
    studentCenterFee = 25;
    calculateTuition(tuitionCostAndFees, tuitionCost, serviceFee, facilitiesFee, studentCenterFee, techFee);//This line seems to be the main problem as to why it won't run!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    calculateTax(tuitionCostAndFees);
    cout << "Your name is: " << name << endl;
    cout << "Your student identification number is: " << SID << endl;
    cout << "Your address is : " << address << endl;
    cout << "You are taking " << credits << " credits this quarter. " << endl;
    cout << "The total cost of your tuition is: $" << tuitionCostAndFees << endl;
    cout << "The total tax deductible amount is: $" << fixed << setprecision(2) << taxDeductible << endl;
    system("pause");
    return 0;
}//function definitions
int getSID(int & SID)
{
    cout << "Enter your student identification number: " << endl;
    cin >> SID;
    return SID;
}
int getResidentStatus(int & residency)
{
    cout << "Are you an international student(1), non-washington resident(2) or washington resident(3)?: " << endl;
    cin >> residency;
    while (!(residency == 1 || residency == 2 || residency == 3))
    {
        cout << "Enter either 1, 2 or 3";
        cin >> residency;
    }
    return residency;
}
double calculateTuition(double & tuitionCostAndFees, double & tuitionCost, double & serviceFee, double facilitiesFee, double & studentCenterFee, double & techFee)
{
    tuitionCostAndFees = tuitionCost + serviceFee + facilitiesFee + studentCenterFee + techFee;
    return tuitionCostAndFees;
}
double calculateTax(double & tuitionCostAndFees, double & taxDeductible)
{
    taxDeductible = tuitionCostAndFees*.125;
    return taxDeductible;
}
#包括
#包括
使用名称空间std;
//下面是我的问题的函数原型
int getSID(int&);
int getResidentStatus(int&);
双重计算工具(双重、双重、双重、双重、双重、双重);
双重计算(双重&);
int main()
{//声明的变量
字符名称[20],地址[30],退伍军人,runningStart;
国际学分,SID,居留权;
双倍学费、免税额、服务费、技术费、设施费、学生中心费、学费和费用;

cout您的老师的意思是,您应该像这样编写代码
void getSID(int&);
并对其定义执行相同的操作。

您已将参数为double的函数CalculateUItion声明为:

calculateTuition(double, double, double, double, double, double);
在按值调用的情况下,将调用此函数

但是,在main之后执行的函数定义中,您尝试通过引用调用参数。这将导致错误。在调用函数时,如下所示:

calculateTuition(tuitionCostAndFees, tuitionCost, serviceFee, facilitiesFee, studentCenterFee, techFee);
您发送的是双倍值(即,声明为:双倍学费成本、免税额、服务费、技术费、设施费、学生中心费、学费成本和费用;)

这将尝试访问上面的函数定义。它不会读取在main之后定义的函数

请尝试以下方法:

calculateTuition(double &, double &, double &, double &, double &, double &);

在你的函数声明中,这应该起作用。

你的教授是否碰巧提到了魔法数字?如果你发现其中一个答案你应该考虑的话。