Witam!
Nie mogę ni jak ogarnąć losowania bez powtórzeń...
kod:
// calculator.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <ctime>
int array[5];
bool repeat = true;
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "hello!" << std::endl;
srand(time_t(NULL));
for (int i = 0; i < 6; ++i){
array[i] = rand() % 100;
for (int j = 0; j < i; j++){
while (repeat){
if (array[j] == array[i]){
array[i] = rand() % 100;
repeat = true;
}
}
}
}
// show
for (int i = 0; i < 6; i++) std::cout << array[i] << "\t";
std::cin.sync();
std::cin.get();
return 0;
}
Albo wyświetla się z powtórzeniami, albo wcale się nie wykonuje ...