카테고리 없음

03-29 C++ 재복습 코드

pp4037 2026. 3. 30. 00:18
#include <iostream>


void PlayerAttack(int* inmonsterHp, const int* inPlayerATK); // 전방선언

void PowerStrike(int* inmonsterHp, const int* inPlayerATK);

int PlayerLevelUp(int level);

int main()
{
	int monsterHp = 20;
	const int PlayerATK = 5;
	static int level = 1;

	std::cout << "Current monster's HP : " << monsterHp << std::endl;

	PlayerAttack(&monsterHp, &PlayerATK);
	PlayerAttack(&monsterHp, &PlayerATK);
	PlayerAttack(&monsterHp, &PlayerATK);

	PowerStrike(&monsterHp, &PlayerATK);

	if (monsterHp <= 0)
	{
		PlayerLevelUp(level);
	}

	return 0;
}

void PlayerAttack(int* inmonsterHp, const int* inPlayerATK)
{
	std::cout << "Player's attack!" << std::endl;

	*inmonsterHp -= *inPlayerATK;

	std::cout << "Current monster's HP : " << *inmonsterHp << std::endl;

	return;
}

void PowerStrike(int* inmonsterHp, const int* inPlayerATK)
{
	std::cout << "player uses a skill!" << std::endl;
	
	int PS = *inPlayerATK * 10;
	*inmonsterHp -= PS;

	return;
}

int PlayerLevelUp(int inlevel)
{
	std::cout << "level Up!" << std::endl;
	++inlevel;

	return inlevel;
}
#include <iostream>

const int monsterHp = 20;
int currentMonster = monsterHp;
const int monsterAtk = 3;
const int monsterDef = 1;
int numberOfMonster = 2;

void PlayerAttack(int* inplayerAtk);
void MonsterAttack(int* inplayerHp, int* inplayerDef);

int main()
{
	int playerHp = 100;
	int playerAtk = 10;
	int playerDef = 1;

	while(numberOfMonster > 0)
	{
		PlayerAttack(&playerAtk);
		MonsterAttack(&playerHp, &playerDef);
	}
	std::cout << "Game Clear" << std::endl;

	return 0;
}

void PlayerAttack(int* inplayerAtk)
{
	std::cout << "currentMonster's HP : " << currentMonster << std::endl;
	std::cout << "Player's attack!" << std::endl;

	currentMonster += monsterDef;
	currentMonster -= *inplayerAtk;

	std::cout << "currentMonster's HP : " << currentMonster << std::endl;

	if (currentMonster <= 0)
	{
		std::cout << "Monster death." << std::endl;
		if (numberOfMonster > 0)
		{
			std::cout << "New Monster Appears." << std::endl;
			currentMonster = monsterHp;
			numberOfMonster -= 1;
		}
		else
		{
			std::cout << "Monster annihilation." << std::endl;
		}
	}

	return;
}

void MonsterAttack(int* inplayerHp, int* inplayerDef)
{
	std::cout << "Player's HP : " << *inplayerHp << std::endl;
	std::cout << "Monster's attack!" << std::endl;
	*inplayerHp += *inplayerDef;
	*inplayerHp -= monsterAtk;
	std::cout << "Player's HP : " << *inplayerHp << std::endl;

	return;
}
#include <iostream>

void C(int* inA, int* inB);

void D(int inC, int inD);

int main()
{
	int A = 5;
	int B = 2;


	C(&A, &B);

	std::cout << A << std::endl;

	A = 5;

	D(A, B);


	return 0;
}


void C(int* inA, int* inB)
{

	*inA /= *inB;

	return;
}

void D(int inC, int inD)
{
	float inE = (float)inC / inD;

	std::cout << inE << std::endl;

}
#include <iostream>
#include <string>

void Question(int inapple);

int main()
{
	int apple;

	std::cout << "우리 딸은 사과 몇 개 먹을래?" << std::endl;
	std::cin >> apple;
	Question(apple);


	return 0;
}

void Question(int inapple)
{
	switch (inapple)
	{
	case 1:
		std::cout << "여기 사과 한 알 먹으렴." << std::endl;
		break;
	
	case 2:
		std::cout << "여기 사과 두 알 먹으렴." << std::endl;
		break;
	
	case 3:
	case 4:
		std::cout << "그건 너무 많아!" << std::endl;
		break;

	default:
	std::cout << "너무 많다니까!" << std::endl;
	break;
	}
}
#include <iostream>
#include <string>

void which(int inA);

int main()
{
	int A;

	std::cout << "숫자를 입력하세요 : " << std::endl;
	std::cin >> A;

	which(A);

	return 0;
}

void which(int inA)
{

	inA < 5 ? std::cout << "숫자가 너무 작아." << std::endl : std::cout << "숫자가 너무 커" << std::endl;


}