开发者

mismatch in formal parameter list

\a3.cpp(75): error C2563: mismatch in formal parameter list

I'm certain I'm passing the function checkout with 3 doubles, I don't know why I'm getting the error I am. Please help.

#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 开发者_如何学Pythonpeanuts";
    cin >> poundsofpeanuts;
    if (!validUserImput(poundsofpeanuts)) cout << "INVALID IMPUT" << endl;
   }
   if (validUserImput == 4) cout << "Total Cost is..." << checkout(amountofbooks, amountofmovies, poundsofpeanuts);
  }
 cin >> amountofbooks;
 }


The problem is here:

if (validUserImput == 4) ...

validUserImput is a function, but you are not calling that function, you are trying to compare it to 4.

If you wanted to keep track of the number of valid inputs you received, you could instead add a new variable that you manually increment on every valid input.


The last if - you are comparing function pointer to an integer. try this:

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


I assume you want to display the result of the checkout function if the user selects 4. So you probably wanted to write:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜