Maximum Score Solutions (While Loop)

Even with a program as small and as simple as this one, there are some minor variations possible. Two slightly different versions are presented here.

Version 1

#include <iostream>
using namespace std;

int main()
{
	int	score;
	int	max = 0;

	cout << "Enter a score (-1 to end): ";
	cin >> score;

	while (score != -1)
	{
		if (score > max)
			max = score;

		cout << "Enter a score (-1 to end): ";
		cin >> score;
	}

	cout << "The maximum score is " << max << endl;

	return 0;
}

Version 2

#include <iostream>
using namespace std;

int main()
{
	int	score;
	int	max;

	cout << "Enter a score (-1 to end): ";
	cin >> score;
	max = score;

	while (score != -1)
	{
		if (score > max)
			max = score;

		cout << "Enter a score (-1 to end): ";
		cin >> score;
	}

	cout << "The maximum score is " << max << endl;

	return 0;
}