2010-10-27 51 views
0

\ a3.cpp(75):錯誤C2563:正式參數列表不匹配不匹配形式參數列表

我敢肯定我傳遞函數收銀臺用3個雙打,我不不知道爲什麼我得到了我的錯誤。請幫忙。

#include <iostream> 
#include <cstdlib> 
using namespace std; 

const double peanut_PRICE = 1.80; 
const double peanut_SHIP = 0.50; 
const double BOOK_PRICE = 9; 
const double BOOK_SHIP = 1.06; 
const double MOVIE_PRICE = 13.99; 
const double MOVIE_SHIP = 0.05; 

double checkout (double myamountofbooks, double myamountofmovies, double mypoundsofpeanuts) 
{ 
    myamountofbooks = myamountofbooks * (BOOK_PRICE + BOOK_SHIP); 
    myamountofmovies = myamountofmovies * MOVIE_PRICE * (1 + MOVIE_SHIP); 
    mypoundsofpeanuts = mypoundsofpeanuts * (peanut_PRICE + peanut_SHIP); 
    return (myamountofbooks + myamountofmovies + mypoundsofpeanuts); 

} 

bool validUserImput (int whereUserWantsToGoNext) 
{ 

    if (whereUserWantsToGoNext > 50 || whereUserWantsToGoNext < 0) 
    return false; 
    else return true; 

} 

bool validUserImput (double whereUserWantsToGoNext) 
{ 

    if (whereUserWantsToGoNext > 50 || whereUserWantsToGoNext < 0) 
    return false; 
    else return true; 

} 

int main() 
{ 
//===========================Declaration Statements================================== 
double amountofbooks = 0; 
double amountofmovies = 0; 
double poundsofpeanuts = 0; 
int whereUserWantsToGoNext = 0; 


    while (! (whereUserWantsToGoNext == 4)) 
    { 
    cout << "1. Books\n2. Peanuts\n3. Movies\n4. Checkout\n" << endl; 
    cin >> whereUserWantsToGoNext; 
    if (!validUserImput(whereUserWantsToGoNext)) cout << "INVALID IMPUT" << endl; 

    if (whereUserWantsToGoNext == 1){ 
    cout << "Please enter your number of books"; 
    cin >> amountofbooks; 
    if (!validUserImput(amountofbooks)) cout << "INVALID IMPUT" << endl; 
    } 

    if (whereUserWantsToGoNext == 3){ 
    cout << "Now please enter the number of movies you've selected"; 
    cin >> amountofmovies; 
    if (!validUserImput(amountofmovies)) cout << "INVALID IMPUT" << endl; 
    } 

    if (whereUserWantsToGoNext == 2) { 
    cout << "Please enter the weight(in pounds) of your peanuts"; 
    cin >> poundsofpeanuts; 
    if (!validUserImput(poundsofpeanuts)) cout << "INVALID IMPUT" << endl; 
    } 
    if (validUserImput == 4) cout << "Total Cost is..." << checkout(amountofbooks, amountofmovies, poundsofpeanuts); 
    } 
cin >> amountofbooks; 
} 
+3

這個詞是「輸入」,如在輸入/輸出。 – 2010-10-27 19:00:14

+0

你的問題是你嘗試結帳的最後一部分的複製/粘貼錯誤。 – 2010-10-27 19:04:56

回答

2

最後一個if - 你將函數指針與一個整數進行比較。試試這個:

if (validUserImput(3) == 4) cout << "Total Cost is..." << checkout(amountofbooks, amountofmovies, poundsofpeanuts); 
+0

你打我吧=/ – 2010-10-27 19:04:21

+0

'validUserImput'返回布爾型 – 2010-10-27 19:11:29

+0

@Charles Salvia validUserImput是一個函數,它將int作爲參數m並返回一個布爾值。如果在調用示例時調用它,它是一個類型爲bool(*)(int)的函數指針,而不是對函數validUserImput – 2010-10-27 19:37:23

2

的問題是在這裏:

if (validUserImput == 4) ... 

validUserImput是一個函數,但是你是不是調用該函數,你試圖把它比作4

如果您想跟蹤收到的有效輸入的數量,則可以添加一個新變量,您可以在每個有效輸入上手動增加一個新變量。

1

我假設你想要顯示checkout函數的結果,如果用戶選擇4。所以你可能想寫:

if (whereUserWantsToGoNext == 4) cout << "Total Cost is..." << checkout(amountofbooks, amountofmovies, poundsofpeanuts) << endl;