#include <iostream>
#include <iomanip>
using namespace std;
//Function prototypes
int getDays();
double getDepartureTime();
double getArrivalTime();
double getAirfareFees();
double getRentalFees();
int getMileageFees();
double getParkingFees(int days);
double getTaxiFees(int days);
double getRegistrationFees();
double getHotelExpenses(int days);
double getBreakfastExpenses(int days, double dTime, double aTime);
double getLunchExpenses(int days, double dTime, double aTime);
double getDinnerExpenses(int days, double dTime, double aTime);
//Global constants
const double MILES = 0.27; //Expense per miles driven
const int PARKING = 6; //Allowed daily parking allowance
const int TAXI = 10; //Allowed daily taxi allowance
const int HOTEL = 90; //Allowed nightly hotel allowance
const int BKFST = 9; //Allowed daily breakfast allowance
const int LUNCH = 12; //Allowed daily lunch allowance
const int DINNER = 16; // ALlowed daily dinner allowance
int main()
{
//Variable Declaration
double grandTotal = 0, //Total expenses incurred
allowedTotal = 0, //Total allowable expenses for the trip
reimburseTotal = 0, //Excess that must be reimbursed, if any
savedTotal = 0, //Amount saved, if any
mealExpenses; //Total cost incurred for meals
//Input & function processing
//Bullet 1
int days = getDays();
{
int getDays();
}
{
int days;
cout << "Enter total of days you'll be staying: ";
cin >> days;
if (days < 0)
cout << "Days cannot be less than 0 \n\n"
<< "Enter total of days you'll be staying again: \n";
cin >> days;
}
//Bullet 2
double dTime = getDepartureTime();
{
double getDepartureTime();
}
{
cout << "Enter your departure time: ";
cin >> dTime;
if (dTime < 0)
{
cout << "Time cannot be less than 0 \n"
<< "Enter departure time again: \n";
cin >> dTime;
}
else if (dTime > 24)
{
cout << "Time cannot exceed more than 24 hours \n"
<< "Enter departure time again: \n";
cin >> dTime;
}
}
這段代碼將被分成單獨的函數,從它的外觀我可能會搞亂。我所擁有的代碼應該在int main之外的獨立函數中,但是我不確定是否正確執行此操作會導致我對這個函數有所瞭解,而且本書中顯示瞭如何構造此函數的錯誤示例。C++函數風格的問題
你的問題是什麼?你的代碼很奇怪。你可能想再次閱讀一些基礎知識。 – 2015-02-11 07:40:08
http://www.cplusplus.com/doc/tutorial/functions/。 – rubikonx9 2015-02-11 07:40:44
您嘗試閱讀有關類和成員函數的內容,通過您的代碼的外觀,將類中的類似函數分組將會更好地滿足您的需求。例如,爲費用,費用,時間,津貼創建班級,並創建獲取和設置功能。它與其他4人組成的團隊項目是 – Sridhar 2015-02-11 07:57:33