我正在尝试制作一个掷骰子,它可以跟踪出现了多少个唯一数字。例如(1 2 3 3 1 5 = 4 个唯一编号,1 1 1 1 1 1 = 1 个唯一编号,1 2 3 4 5 6 = 6 个唯一编号)。但每次它只返回一个“0”来表示唯一数字的数量。任何人都可以帮忙吗?
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int numberGenerator() //generates 1-6
{
int x = (rand() % 6) + 1;
return x;
}
int diceCounter()
{
int counter[6] = {0,0,0,0,0,0};
for (int i = 0; i > 6; i++)
{
int k = numberGenerator(); //records if the dice number has been rolled
if (k == 1)
counter[0] = 1;
if (k == 2)
counter[1] = 1;
if (k == 3)
counter[2] = 1;
if (k == 4)
counter[3] = 1;
if (k == 5)
counter[4] = 1;
if (k == 6)
counter[5] = 1;
}
return counter[0]+counter[1]+counter[2]+counter[3]+counter[4]+counter[5];
} //returns amount of unique dice numbers
int main()
{
srand(time(NULL));
cout << diceCounter() << endl;
}