2016-10-12 65 views
0

這是一個程序,我做編程類,是應該根據加班時間半計算人的工資,但它打破了,我不知道爲什麼。我非常基本的C++程序破產了,我不知道爲什麼

事情會輸出「」「」有工作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; 

} 
+5

歡迎堆棧溢出的概念!這聽起來像你可能需要學習如何使用調試器來逐步執行代碼。憑藉良好的調試器,你可以執行你的程序一行一行,看看它在哪裏偏離你期望的地方,如果你打算做任何編程,這是一個必不可少的工具。調試小程序](http://ericlippert.com/2014/03/05/how-to-debug-small-programs/)** – NathanOliver

+3

解決此類問題的正確工具是您的調試器。在*堆棧溢出問題之前,您應該逐行執行您的代碼。如需更多幫助,請閱讀[如何調試小程序(由Eric Lippert撰寫)](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)。至少,您應該\編輯您的問題,以包含一個[最小,完整和可驗證](http://stackoverflow.com/help/mcve)示例,該示例再現了您的問題,以及您在調試器。 –

+0

不知道你應該這樣做。謝謝。 – Logan87654321

回答

0

你的函數所有正在返回值。你在哪裏存儲它?倍數回報不可能的,因爲你正在使用。嘗試指針(引用)

相關問題