๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โœ’๏ธ C Programming/๋ˆ„๊ตฌ๋‚˜ ์‰ฝ๊ฒŒ ์ฆ๊ธฐ๋Š” C ์–ธ์–ด ์ฝ˜์„œํŠธ_๊ฐœ์ • 3ํŒ

[๋ˆ„๊ตฌ๋‚˜ ์‰ฝ๊ฒŒ ์ฆ๊ธฐ๋Š” C ์–ธ์–ด ์ฝ˜์„œํŠธ - ๊ฐœ์ • 3ํŒ] 6์žฅ Mini Project ๋ฌธ์ œ ํ’€์ด

by A Lim Han 2023. 1. 12.

# 6์žฅ Mini Project ๋ฌธ์ œ ํ’€์ด

 

 

246p Mini Project)

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
	int init = 12;
	int computer = 0;
	int user = 0;

	srand(time(NULL));

	do
	{
		printf("ํ˜„์žฌ ์Šคํ‹ฑ์˜ ๊ฐœ์ˆ˜: %d\n", init);
		printf("๋ช‡ ๊ฐœ์˜ ์Šคํ‹ฑ์„ ๊ฐ€์ ธ๊ฐ€์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?: ");
		scanf_s("%d", &user);
		init -= user;

		if (init <= 0)
		{
			printf("์ปดํ“จํ„ฐ ์Šน๋ฆฌ");
			break;
		}

		computer = rand() % 4;	//0~3 ์‚ฌ์ด์˜ ๋‚œ์ˆ˜๋ฅผ ๋งŒ๋“œ๋ ค๋ฉด 4๋กœ ๋‚˜๋ˆ ์ค˜์•ผ ํ•จ

		printf("**์ปดํ“จํ„ฐ๋Š” %d๊ฐœ์˜ ์Šคํ‹ฑ์„ ๊ฐ€์ ธ๊ฐ”์Šต๋‹ˆ๋‹ค.\n\n", computer);
		init -= computer;

		if (init <= 0)
		{
			printf("์‚ฌ์šฉ์ž ์Šน๋ฆฌ");
			break;
		}
	} 
	while (init > 0);

	return 0;
}