Code mô phỏng game bầu cua bị lỗi

#include<stdio.h>
#include<conio.h>
#include<time.h>
#include<stdlib.h>
#include<windows.h>

int main()
{
	int n;
	int sotienbd = 100000;
	int sotienconlai;
	int check;
	int ca =0;
	int nai=0;
	int bau=0;
	int ga=0;
	int tom=0;
	int cua=0;
	printf("\tGAME BAU CUA CA - made by Dang Quoc Huy");
	huy:
	printf("\n MENU");	
	printf("\n1 - Dat cuoc");
	printf("\n2 - Play");
	printf("\n3 - Exit");
	do{
		printf("\nNhap lua chon chua ban :");
		scanf("%d", &n);
		if (n > 3 || n < 1)
			printf("\nLua chon khong hop le!!!");
	} while (n < 1 || n > 3);
	if (n == 1)
	{
		if (sotienbd < 0)
		{
			printf("\nSo tien con lai cua ban la: %d", sotienconlai);
		}
		else
		{
			printf("So tien ban dau cau ban: %d", sotienbd);
		}
		printf("\nBan dat cuoc cho ca :");
		scanf("%d", &ca);
		check = 1;
		
		sotienbd -= ca;
		if (sotienbd < 0)
		{
			
			printf("\nBan khong du tien cuoc");
			ca = 0;
			printf("\nSo tien con lai cua ban la: %d", sotienbd);
			printf("\nBan muon dat cuoc tiep(bam 1) hay la play(bam 2): ");
			goto huy;
		}
		printf("Ban dat cuoc cho nai :");
		scanf("%d", &nai);
		check = 2;
		sotienconlai = sotienbd;
		sotienbd -= nai;
		if (sotienbd < 0)
		{
			printf("\nBan khong du tien cuoc");
			nai = 0;
			printf("\nSo tien con lai cua ban la: %d", sotienconlai);
			printf("\nBan muon dat cuoc tiep(bam 1) hay la play(bam 2): ");
			goto huy;
		}
		printf("Ban dat cuoc cho bau :");
		scanf("%d", &bau);
		check = 3;
		sotienconlai = sotienbd;
		sotienbd -= bau;
		if (sotienbd < 0)
		{
			printf("\nBan khong du tien cuoc");
			bau = 0;
			printf("\nSo tien con lai cua ban la: %d", sotienconlai);
			printf("\nBan muon dat cuoc tiep(bam 1) hay la play(bam 2): ");
			goto huy;
		}
		printf("Ban dat cuoc cho ga :");
		scanf("%d", &ga);
		check = 4;
		sotienconlai = sotienbd;
		sotienbd -= ga;
		if (sotienbd < 0)
		{
			printf("\nBan khong du tien cuoc");
			ga = 0;
			printf("\nSo tien con lai cua ban la: %d", sotienconlai);
			printf("\nBan muon dat cuoc tiep(bam 1) hay la play(bam 2): ");
			goto huy;
		}
		printf("Ban dat cuoc cho tom :");
		scanf("%d", &tom);
		check = 5;
		sotienconlai = sotienbd;
		sotienbd -= tom;
		if (sotienbd < 0)
		{
			printf("\nBan khong du tien cuoc");
			tom = 0;
			printf("\nSo tien con lai cua ban la: %d", sotienconlai);
			printf("\nBan muon dat cuoc tiep(bam 1) hay la play(bam 2): ");
			goto huy;
		}
		printf("Ban dat cuoc cho cua : ");
		scanf("%d", &cua);
		check = 6;
		sotienconlai = sotienbd;
		sotienbd -= cua;
		if (sotienbd < 0)
		{
			printf("\nBan khong du tien cuoc");
			cua = 0;
			printf("\nSo tien con lai cua ban la: %d", sotienconlai);
			printf("\nBan muon dat cuoc tiep(bam 1) hay la play(bam 2): ");
			goto huy;
		}
		else
		{
			printf("\nSo tien con lai cua ban la: %d", sotienconlai);
			goto huy;
		}
	}
	if (n == 2)
	{
		printf("\n BAT DAU DO XUC SAC!!!");
		int x;
		int sotienthuong = 0;
		int sotienlucsau = 0;
		for (int i = 1; i <= 3; i++)
		{
			printf("\n XUC SAC THU %d", i);
			Sleep(1000);
			//srand(time(0));
			int x;
			x = 1 + rand() % 6;
			srand(time(0));
			if (x == 1)
			{
				printf("\nCa");
				sotienthuong += ca;
				printf("\nSo tien thang duoc : %d", sotienthuong);
				sotienlucsau = sotienthuong + sotienconlai;
				//printf("\nSo tien sau khi choi: %d ", sotienlucsau);
			}
			if (x == 2)
			{
				printf("\nNai");
				sotienthuong += nai;
				printf("\nSo tien thang duoc : %d", sotienthuong);
				sotienlucsau = sotienthuong + sotienconlai;
				//printf("\nSo tien sau khi choi: %d ", sotienlucsau);
			}
			if (x == 3)
			{
				printf("\nBau");
				sotienthuong += bau;
				printf("\nSo tien thang duoc : %d", sotienthuong);
				sotienlucsau = sotienthuong + sotienconlai;
				//printf("\nSo tien sau khi choi: %d ", sotienlucsau);
			}
			if (x == 4)
			{
				printf("\nGa");
				sotienthuong += ga;
				printf("\nSo tien thang duoc : %d", sotienthuong);
				sotienlucsau = sotienthuong + sotienconlai;
				//printf("\nSo tien sau khi choi: %d ", sotienlucsau);
			}
			if (x == 5)
			{
				printf("\nTom");
				sotienthuong += tom;
				printf("\nSo tien thang duoc : %d", sotienthuong);
				sotienlucsau = sotienthuong + sotienconlai;
				//printf("\nSo tien sau khi choi: %d ", sotienlucsau);
			}
			if (x == 6)
			{
				printf("\nCua");
				sotienthuong += cua;
				printf("\nSo tien thang duoc : %d", sotienthuong);
				sotienlucsau = sotienthuong + sotienconlai;
				///printf("\nSo tien sau khi choi: %d ", sotienlucsau);
				
			}
			//printf("\nSo tien sau khi choi: %d ", sotienlucsau);
		}
		printf("\nSo tien sau khi choi: %d ", sotienlucsau);
	}
	if (n == 3)
	{
		return 0;
	}
	getch();
	return 0;
}

em mới làm ra game bầu cua này, mong mọi người góp ý. Còn 2 vấn đề là lúc mới đầu vào mà chọn số 2 sẽ lỗi ngay và khi em chọn release trong visual thì bị lỗi này

1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?