Commit 8e9947c1 authored by Karine's avatar Karine

exercise_06_42, version2

parent 13dbdb7b
......@@ -4,7 +4,8 @@
void
hanoi(const int count, const int start, const int temp, const int end)
{
assert(count > 0);
assert(count > 0 && start > 0 && temp > 0 && end > 0);
assert(start != end);
if (1 == count) {
std::cout << start << "-->" << end << std::endl;
} else {
......@@ -28,15 +29,19 @@ main()
int start;
int end;
int temp;
std::cout << "Enter the numbers for start, temporary, end pegs (from 1 to 3): ";
std::cin >> start >> temp >> end;
if ((start < 1 && start > 3) || (temp < 1 && temp > 3) || (end < 1 && end > 3)) {
std::cerr << "Error 2: Invalid value for pegs." << std::endl;
std::cout << "Enter the numbers for start, end pegs (from 1 to 3): ";
std::cin >> start >> end;
int temp = 6 - (start + end);
if (start == end) {
std::cerr << "Error 2: Numbers for start and end pegs can't be the same." << std::endl;
return 2;
}
if ((start < 1 && start > 3) || (end < 1 && end > 3)) {
std::cerr << "Error 3: Invalid value for pegs." << std::endl;
return 3;
}
hanoi(count, start, temp, end);
......
Enter the count of disks: Enter the numbers for start, temporary, end pegs (from 1 to 3): 1-->2
Enter the count of disks: Enter the numbers for start, end pegs (from 1 to 3): 1-->2
1-->3
2-->3
1-->2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment