gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 04:11:42 25 4
gpt4 key购买 nike

这是我们一直在为我的 100 级类(class)解决的一个特殊问题,我们最近在代码中添加了函数。我似乎可以确切地弄清楚如何才能让这段代码运行。另外,我的老师说我的变量 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;
}

最佳答案

你的老师的意思是你应该这样编码 void getSID(int &); 并且对它的定义做同样的事情。

关于c++ - 特殊学校代码处理函数和返回值问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20136522/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com