Итак, я пытаюсь написать этот код, который должен сгенерировать сумму двух разных чисел и определить, выиграл ли игрок или проиграл или нет в соответствии с указанной суммой. А затем приступите к вычислению бюджета игрока в соответствии с их статусом. Я продолжаю получать «» аргумент типа «Int (*)()» несовместим с параметром типа междунара»ошибка, и я не знаю, почему."Аргумент типа" int (*)() "несовместим с параметром типа int" error?
#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;
}
'bool win_or_loss (int sum, double budget, double bet);' Это не то, как вы вызываете функцию ... и 'int sum();' прямо перед тем, как объявить другую функцию, называемую суммой, не принимающей никаких параметров и возвращающей ее , это не переменная типа int. – Borgleader
'int sum() {int sum;/** /} ', Избегайте использовать одно и то же имя для переменной и функции ... – Jarod42
' int sum(); bool win_or_loss (int sum, double budget, double bet); '- Возможно, вам следует объяснить, каковы ваши намерения с этим кодом. – PaulMcKenzie