본문 바로가기
Computer Science/C++

C++ -4- While 반복문과 함수를 이용한 간단한 덧셈 계산기

by Choi Seung Hyeok 2021. 4. 5.
#include <iostream>

using namespace std;

int plus5(int num_a, int num_b)
{
	int sum = num_a + num_b;
	return sum;
}
int main()
{

		while (1)
		{
			int x, y;
			cin >> x >> y;
			cout << "x + y의 값은 " << plus5(x, y) << "입니다." << endl;

		}


	

	return 0;
}

while(1) 또는 while(true)를 이용해 무한정으로 cin을 통해 값을 넣고 결과를 도출할 수 있다.

댓글