"аргумент типа" int(*)() "несовместим с параметром типа int" ошибка?
Поэтому я пытаюсь написать этот код, который должен генерировать сумму из двух разных чисел и определить, выиграл игрок или проиграл, или нет, в соответствии с указанной суммой. А затем приступить к расчету бюджета игрока в соответствии с его статусом. Я продолжаю получать "" аргумент типа "int(*)()" несовместим с параметром типа int "ошибка, и я не уверен, почему.
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
//prototyping functions
int sum();
int bla(int, int, int, int);
void main()
{
//declaring variables
int budget, bet, new_budget;
string yes_no;
//inputting budget
cout << "Please enter your budget: ";
cin >> budget;
//inputting bet
cout << "Please enter your bet: ";
cin >> bet;
//validating bet and budget
if (bet > budget)
{
cout << "Error, bet cannot be larger than budget. Please reenter your budget and bet, respectively: ";
cin >> budget;
cin >> bet;
}
else //calling functions
{
double m = sum();
double n = bla(sum, budget, bet, new_budget);
}
//asks player if they would like play again
cout << "Would you like to play again? Enter Y for Yes or N for No";
cin >> yes_no;
//repeats program
if (yes_no == "Y" && (new_budget > 0))
{
cout << "Please enter your budget: ";
cin >> budget;
cout << "Please enter your bet: ";
cin >> bet;
if (bet > budget)
{
cout << "Error, bet cannot be larger than budget. Please reenter your budget and bet, respectively: ";
cin >> budget;
cin >> bet;
}
else
{
int sum();
bool win_or_loss(int sum, double budget, double bet);
}
}
system("pause");
}
int sum() //calculates the sum of the dice
{
int x;
int y;
int sum;
x = rand() % 7;
y = rand() % 7;
sum = x + y;
cout << "The sum of the two dice is " << sum << endl;
return sum;
}
int bla(int sum, int budget, int bet, int new_budget) //calculates the new budget according to whether the player won or lost or neither
{
bool flag = false;
if ((sum == 7) || (sum == 11))
{
cout << "You have won" << endl;
new_budget = budget + bet;
flag = true;
}
else if ((sum == 2) || (sum == 3) || (sum == 12))
{
cout << "You have lost" << endl;
new_budget = budget - bet;
flag = false;
}
else
{
cout << "Neither win or loss, please generate new numbers" << endl;
int sum();
flag = false;
}
return new_budget;
}
1 ответ
Решение
int bla(int, int, int, int);
bla
функция ожидает int
аргументы но
double n = bla(sum, budget, bet, new_budget);
вы проходите sum
в качестве параметра, который является функцией. Как твой sum
функция возвращает int
Вы можете передать это как sum()
double n = bla(sum(), budget, bet, new_budget);
Примечание стороны: внутри sum
Функция, которую вы объявили переменную с именем sum
, Избегайте использования одного и того же имени для функции и переменной. Это вызывает двусмысленность.