guess the sign(game)

you have a set of different colored signs, each with a number on it. the set is randomized and then you show the player one sign, he has to guess whether the next sign will have a larger or a smaller number, and he bets on it. so the set is then randomized again and the next sign is revealed, and if his answer was correct he wins the bet, if it was wrong, he loses the bet.
So, here's my code, I think it's working fine till the point where I input my bet, after that I get nothing. I understand my problem might be mainly in the if statements and their arguments where I'm trying to compare the guessed answer with the newly shown sign.

Thanks for any help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <ctime>
#include <string>
using namespace std;

//function declaration  (function for randomizing the set of pictures)
void randomize(int[][2]);

int main()
{
    double totalMoney; //the player's total amount of money
    int userIn;  //the answer to "is next number smaller or bigger"?
    double betMoney;  //the player's bet
    int lastPicture;
    
    cout << "How much money do you have ? ";
    cin >> totalMoney;
    
    int j;
    int picture[75][2];  // the shown picture
    
    int number[15]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; //array of picture numbers
    
    string color[5]={"blue","green","yellow","red","black"};    //array of picture colors
    
    srand(time(0));
    randomize(picture);  // run the randomizing function
    
    lastPicture = number[picture[j][1]];
    
    cout<<"Picture number/color is: "<< number[picture[j][1]]<<" / "<< color[picture[j][0]]<<endl;
    
    cout << "Will the next picture have a bigger/smaller number ? type 0 for bigger, 1 for smaller ";
    cin >> userIn;  //the answer
    
    cout << "How much do you bet on that ? ";
    cin >> betMoney;
    
    
    // if his answer is 0 (bigger), and it's correct (true)/number is bigger than last number:
    if (userIn == 0 && (number[picture[j][1]]) > lastPicture)
    {
        cout<<"correct."<<betMoney<<"is added to your money. "<<"your total now is: "<<betMoney+totalMoney<< endl;
    }
    
    // if his answer is 0 (bigger), but it's incorrect (false)/number isn't bigger than last number
    else if (userIn == 0 && (number[picture[j][1]]) < lastPicture)
    {
        cout<<"incorrect."<<betMoney<<"is deducted from your money. "<<"your total now is: "<<totalMoney-betMoney<< endl;
    }
    
    // if his answer is 1 (smaller), and it's correct (true)/number is smaller than last number
    else if (userIn == 1 && (number[picture[j][1]]) < lastPicture)
    {
        cout<<"correct."<<betMoney<<"is added to your money"<<"your total now is: "<<betMoney+totalMoney<< endl;
    }

    // if his answer is 1 (smaller), but it's incorrect (false)/number isn't smaller than last number
    else if (userIn == 1 && (number[picture[j][1]]) > lastPicture)
    {
        cout<<"incorrect."<<betMoney<<"is deducted from your money. "<<"your total now is: "<<totalMoney-totalMoney<< endl;
    }
     
    lastPicture = number[picture[j][1]];
    
    return 0;
}


//function definition   (function for randomizing the set of pictures)
void randomize(int pics[][2])
{bool pictures[5][15];
    int i,j,num,col;
    for(i=0;i<5;i++)
        for(j=0;j<15;j++)
            pictures[i][j]=false;
    
    for(j=0;j<75;j++)
    {do
    {
        num=rand()%15;
        col=rand()%5;
    }while(pictures[col][num]);
        pics[j][0]=col;
        pics[j][1]=num;
        pictures[col][num]=true;
    }
    
    return;
}
Last edited on
Topic archived. No new replies allowed.