这是我正在为编程课做的一个程序,它应该根据加班时间和一半来计算人们的工资,但它已经破了,我不明白为什么。
东西将输出“”“”有工作6942646并且工作6923592小时“或类似的东西。
#include <iostream>
#include <iomanip>
using namespace std;
string getName(string, string);
int getJob(int&);
int hoursWorked(int);
double jobCalc(int&, int&, double&);
void display(string, string, int, int, double);
int main()
{
int job;
int hours;
double pay;
string firstname, lastname;
getName(firstname, lastname);
getJob(job);
hoursWorked(hours);
jobCalc(job, hours, pay);
display(firstname, lastname, job, hours, pay);
return 0;
}
string getName(string firstname, string lastname)
{
cout << "Enter your name (First): ";
cin >> firstname;
cout << "Enter your name (Last): ";
cin >> lastname;
return firstname, lastname;
}
int getJob(int job&)
{
cout << "Yo What motha duckin job number is you? Ya' dig? (10, 20, or 30): ";
cin >> job;
bool jobNo = false;
while (jobNo = false)
{
if (job == 10)
{
jobNo = true;
}
else if (job == 20)
{
jobNo = true;
}
else if (job == 30)
{
jobNo = true;
}
else if (job < 9 || job > 11 || job < 19 || job > 21 || job < 29 || job > 31)
{
cout << "Yo! Please re-enter a correct value. What it is, mostly, Mama! Don't make me shank ya!" << endl;
cout << "Yo What motha' duckin' job number is you? Ya' dig? (10, 20, or 30): ";
cin >> job;
}
}
return job;
}
int hoursWorked(int hours)
{
cout << "Yo! How geezery hours dahd ya work?: ";
cin >> hours;
return hours;
}
double jobCalc(int& job, int& hours, double& pay)
{
if (job == 10)
{
if (hours < 40)
{
pay = hours * 8.75;
}
else if (hours < 60)
{
pay = 8.75 * 40;
hours = hours - 40;
pay = pay + (hours * 13.125);
}
else
{
pay = 8.75 * 40;
pay = pay + (13.125 * 20);
hours = hours - 60;
pay = pay + (17.5 * hours);
}
}
else if (job == 20)
{
if (hours < 40)
{
pay = hours * 12.25;
}
else if (hours < 60)
{
pay = 12.25 * 40;
hours = hours - 40;
pay = pay + (hours * 18.375);
}
else
{
pay = 12.25 * 40;
pay = pay + (18.375 * 20);
hours = hours - 60;
pay = pay + (24.5 * hours);
}
}
else if (job == 30)
{
if (hours < 40)
{
pay = hours * 13.75;
}
else if (hours < 60)
{
pay = 13.75 * 40;
hours = hours - 40;
pay = pay + (hours * 20.625);
}
else
{
pay = 13.75 * 40;
pay = pay + (20.625 * 20);
hours = hours - 60;
pay = pay + (27.5 * hours);
}
}
return pay;
}
void display(string firstname, string lastname, int job, int hours, double pay)
{
std::cout << std::fixed;
std::cout << std::setprecision(2);
cout << firstname << " " << lastname << " has job " << job << " and worked " << hours << " hours, thus earning them $" << setprecision(2) << pay << "." << endl;
}
答案 0 :(得分:0)
所有函数都返回值。你在哪里存放它?您正在使用多次返回。尝试指针(参考)的概念