形式参数列表中的不匹配

时间:2010-10-27 18:50:41

标签: c++ function parameters

  

\ 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 个答案:

答案 0 :(得分:2)

最后一个if - 您将函数指针与整数进行比较。试试这个:

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

答案 1 :(得分:2)

问题在于:

if (validUserImput == 4) ...

validUserImput是一个函数,但您没有调用该函数,而是尝试将其与4进行比较。

如果您想跟踪收到的有效输入数量,可以添加一个新变量,在每个有效输入上手动递增。

答案 2 :(得分:1)

如果用户选择checkout,我假设您要显示4函数的结果。所以你可能想写:

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