-4

I'm coding a game of farkle, and I run into this problem even though all but two of my if statements are bools.

Also, how would I go about letting a user roll specific dice? BloodshedDev/othre IDEs seem to not be working in windows 8 yet, so I'm using Ideone and having zero luck with any of this.

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

//global vars
int bubblehold;
int roll[6];
int score;
int bank;
int dicecatch;
int tempscore = 0;
int dicenum = 6;

//function prototype
void bubblesort(int[], int);
bool straightsix();
bool sixkind();
bool fivekind();
bool fourkind();
bool threekind();
int onefive();

int main() {
    srand(time(0));
        for(int i=0; i=dicenum-1; i++){
        roll[i] = rand()%6+1;
    }
    bubblesort(roll,dicenum);
    for(int i=0; i=dicenum-1; i++){
        cout<< roll[i] <<", ";
    }

    if(straightsix == true){
        tempscore = 1500;

    }
    else if(sixkind == true){
        tempscore = 3000;

    }
    else if(fivekind == true){
        tempscore = 2000;

    }
    else if(fourkind == true){
        tempscore = 1000;
    }
    else if(threekind == true){
        cout<< tempscore;
    }
    else if(onefive == 1){
        tempscore = dicecatch * tempscore;
        cout<< tempscore;
    }
    else if(onefive == 5){
        tempscore = dicecatch * tempscore;
        cout<< tempscore;
    }

    return 0;
}
void bubblesort(int a[], int x){
    for (int i = 0; i < x-1; i++){
        bubblehold = a[i+1];
        a[i+1] = a[i];
        a[i] = bubblehold;
    }
}
bool straightsix(){
    for(int i=0; i<5; i++){
        if(roll[i]+1 != roll[i+5]){
            return false;
        }
    }
}
bool sixkind(){
    for(int i=0; i=5; i++){
        if (roll[i] != roll[i+5]){
            return false;
        }
    }
}
bool fivekind(){
    for(int i=0; i=4; i++){
        if (roll[i] != roll[i+4]){
            return false;
        }
    }
}
bool fourkind(){
    for(int i=0; i=3; i++){
        if (roll[i] != roll[i+3]){
            return false;
        }
    }
}
bool threekind(){
    for(int i=0; i=2; i++){
        if (roll[i] != roll[i+2]){
            return false;
        }
        else if(i=1){
            dicecatch = 3;
            tempscore = dicecatch * 100;
            return true;
        }
        else{
            dicecatch = i;
            tempscore = dicecatch * 100;
            return true;
        };
    }
}

int onefive(){
    for(int i=0; i=dicenum; i++){
        if(roll[i] == 1){
            dicecatch = dicecatch + 1;
            tempscore = tempscore + 100;
            return 1;
        }
        else if(roll[i] == 5){
            dicecatch = dicecatch + 1;
            tempscore = tempscore + 50;
            return 5;
        }
    }
}
user2320765
  • 1
  • 1
  • 1

2 Answers2

0

In this line,

if(straightsix == true){

you are comparing a function pointer with true. You have similar statements involving other functions.

Perhaps you meant to use:

if(straightsix() == true){

In that case, it can be simplified to:

if(straightsix()){
R Sahu
  • 204,454
  • 14
  • 159
  • 270
0

Expanding a bit the answer of R Sahu, the difference is effectively just the added parenthesis, but I would like to add the reason.

In C++ (and actually all other C-style languages I know of) when you're referring to functions having parenthesis is a big difference. Putting them on means that the code will call the function, execute all its code, and whatever it returns will be used in the comparison afterwards. The parenthesis also are a fundamental syntax for passing parameters, and are mandatory even if you don't pass any when calling, unlike basic-style languages and many others.

Omitting parenthesis has a radically different meaning. Instead of instructing execution of a function, it will return a pointer to the function and will never run any of its code. That pointer is obviously not a boolean and neither an int, that gives the compiler error most likely. All your if in the main have this problem.

A correct usage of function calls are the initial call to time and srand, including the parenthesis and argument (a zero) within them.

Community
  • 1
  • 1
Alejandro
  • 7,290
  • 4
  • 34
  • 59