// 32_32-2.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include "stdafx.h"
#include <iostream>
#include <windows.h>

using namespace std;

int total(int n)	// 1〜nまでの総和を計算
{
	int i, sum = 0;

	if (n < 1) throw "不正な数値です。";	// 例外発生
	for (i = 1; i <= n; i++) {
		sum += i;
	}
	return sum;
}

int _tmain(int argc, _TCHAR* argv[])
{
	int n = 0, ans;

	cout << "数値=";
	cin >> n;

	try {
		ans = total(n);
		cout << "1〜" << n << " の総和は " << ans << '\n';
	}
	catch (const char *e) {
		cout << "ERR: " << e << '\n';
		MessageBox(NULL, _T("Check Console Window"), L"MessageBox", MB_OK);
		return 1;
	}

	MessageBox(NULL, _T("Check Console Window"), L"MessageBox", MB_OK);

	return 0;
}

