Code: Game bài cào
#include <bits/stdc++.h>
#include <cstdlib>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include <windows.h>
using namespace std;
// BAMBOO BY CODE CASINO "RED - BLACK"
int count(int n)
{
int j = 0;
while(n != 0)
{
int t = n % 10;
j++;
n = n / 10;
}
return j;
}
struct Info
{
long cost;
char name[50];
int c = rand() % (10 - 0 + 1) + 0;
int d = rand() % (10 - 0 + 1) + 0;
int e = rand() % (10 - 0 + 1) + 0;
int sum = c + d + e;
};
void Input_Array(Info a[] , int n)
{
for(int i = 0 ; i < n ; i++)
{
cout<<"Player "<<i+1<<endl;
cout<<"Input cost: ";
cin>>a[i].cost;
fflush(stdin);
cout<<"Name player: ";
gets(a[i].name);
}
}
void Output(Info a[] , int n)
{
int MAX = 0 , num[100000] , x =0;
for(int i = 0 ; i < n ; i++)
{
cout<<"-------------------------------"<<endl;
cout<<"Name Player: "<<a[i].name<<endl;
cout<<"Gia tri 3 la bai lan luot la: ";
cout<<a[i].c<<" "<<a[i].d<<" "<<a[i].e<<endl;
cout<<"Tong 3 la bai: ";
int k = a[i].sum;
num[x++] = k;
if(count(k) == 2)
cout<<"Point: "<<k % 10<<endl;
if(count(k) == 1)
cout<<"Point: "<<k<<endl;
if(MAX < k)
MAX = k;
}
int sum_cost = 0;
for(int i = 0 ; i < n ; i++)
sum_cost += a[i].cost;
int z=0,f;
for(int i = 0 ; i < x ; i++)
{
if(MAX == num[i])
{
z++;
f = i;
}
}
cout<<"-----------------------"<<endl;
if(z == 1)
{
cout<<"YOU WIN"<<endl;
cout<<"Player Name WIN: "<<a[f].name<<endl;
cout<<"MONEY WIN: "<<sum_cost<<" VND";
}
if(z > 1)
cout<<"DRAW";
}
int main()
{
int n;
cin>>n;
Info a[n];
Input_Array(a,n);
Output(a,n);
return 0;
}