#include using namespace std; /* Kullanıcıdan atılacak zar sayısını alıp, Onun yerine zarları atıp kazananı ve kaybedeni ekrana yazan programı yazınız. rand() fonksiyonu ile random bir sayı döndürülür. Dönen random sayının değer aralığı çok fazla olduğu için basit bir mod alma işlemi ile istediğimiz değerlere indirgeyebiliriz. Örneğin: rand()%100 ==> 0 ile 99 arasında sayı döndürür. rand()%100 + 1 ==> 1 ile 100 arasında bir sayı üretir. O yüzden biz 1 ile 6 arasında çevirmesini istiyorsak rand()%6+1 komutunu kullanmamız gerekli. */ int main() { int time, firstMan=0, SecondMan=0; cout << "Enter the number of shots: "; cin >> time; for (int i = 0; i < time; i++){ int temp1, temp2; temp1 = rand()%6+1; temp2 = rand()%6+1; cout << "First guy shoted " << temp1 << endl; cout << "Second guy shoted " << temp2 << endl; cout << "-------------------" << endl; if (temp1 > temp2) firstMan++; if (temp2 > temp1) SecondMan++; else { firstMan++; SecondMan++; } } if (firstMan > SecondMan) cout << "\nFirst guy won!" << endl; else if ( SecondMan > firstMan) cout << "\nSecond guy won!" << endl; else { cout << "Draw!" << endl; } }