Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to check if an array equals any other array C++?
    primarykey
    data
    text
    <p>I'm trying to make a dice program in C++. In that program, I have a function called "bool_if" (Don't ask me why I named some things the way I did, I made this program for me and I don't want to change variable/function names). I want bool_if() to check if any elements in the array rolled_die[] is the same. Sorry if that doesn't make sense, here's the source code (I commented in part of the source code for what I want):</p> <pre><code>#include &lt;cstdlib&gt; #include &lt;ctime&gt; #include &lt;iostream&gt; #include &lt;unistd.h&gt; #include &lt;fstream&gt; using namespace std; void clear() { cout&lt;&lt;"\033[2J\033[1;1H"; } bool rolled_die[5]; void dice() { if (die[0] == die[1] || die[0] == die[2] || die[0] == die[3] || die[0] == die[4] || die[0] == die[5]) { rolled_die[0] = true } else if (die[1] == die[2] || die[1] == die[3] || die[1] == die[4] || die[1] == die[5]) { rolled_die[1] = true } else if (die[2] == die[3] || die[2] == die[4] || die[2] == die[5]) { rolled_die[2] = true } else if (die[3] == die[4] || die[3] == die[5]) { rolled_die[3] = true } else if (die[4] == die[5]) { rolled_die[4] = true } } int finished_score = 0 void bool_if { if (rolled_die[0] == true || rolled_die[1] == true || rolled_die[2] == true || rolled_die[3] == true || rolled_die[4] == true) { finished_score++; } /* In this part, I need to check if rolled_die[0] is equal to rolled_die[1], or rolled_die[2], etc all the way up to rolled_die[5]. */ int main() { srand(time(0)); int die[6] = { (rand()%6)+1,(rand()%6)+1, (rand()%6)+1, (rand()%6)+1, (rand()%6)+1, (rand()%6)+1 }; int bet; ifstream a_file ("Score.txt"); if ( !a_file.is_open() ) { clear(); cout&lt;&lt;"Score file could not be loaded. Maybe file doesn't exist?\n"; return 0; } int score; a_file&gt;&gt; score; clear(); cout&lt;&lt;"How much would you like to bet?\nRemember, you only have $"&lt;&lt; score &lt;&lt;"!\nEnter your bet: "; cin&gt;&gt; bet; if ( bet &gt; score ) { clear(); cout&lt;&lt;"You bet more money then you have!\n"; return 0; } clear(); cout&lt;&lt;"Rolling...\n"; usleep(0.1 * 1000000); cout&lt;&lt;"First die: " &lt;&lt; die[0] &lt;&lt;"\n"; usleep(1.3 * 1000000); cout&lt;&lt;"Second die: " &lt;&lt; die[1] &lt;&lt;"\n"; usleep(0.3 * 1000000); cout&lt;&lt;"Third die: " &lt;&lt; die[2] &lt;&lt;"\n"; usleep(2 * 1000000); cout&lt;&lt;"Fourth die: " &lt;&lt; die[3] &lt;&lt;"\n"; usleep(0.3 *1000000); cout&lt;&lt;"Fifth die: " &lt;&lt; die[4] &lt;&lt;"\n"; usleep(1.2 * 1000000); cout&lt;&lt;"Sixth die: " &lt;&lt; die[5] &lt;&lt;"\n"; cout&lt;&lt;"\n\nPress enter to see how you fared."; cin.get(); clear(); return 0; } </code></pre> <p>Also please tell the function dice() doesn't work. I want dice() to check for any pairs.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload