#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int numRabbits, numChicken, totalFeet; char again = 'Y'
bool checkSolution = true;
do{
cout << "總共有幾隻腳?" << endl;
cin >> totalFeet;
if((totalFeet%2) != 0)
cout << "沒有一支腳的雞或兔子 ˋˊ" << endl;
else if(totalFeet == 0)
cout << "籠子裡沒有東西 = =" << endl;
if((totalFeet%2) != 0 || totalFeet == 0) {checkSolution = false; again == 'Y'}
else again++;
} while(again == 'Y');
cout << '\n' << "有這幾種可能性" << endl;
cout << setw(8) << "兔" << " | " << setw(8) << "雞" << '\n'
cout << "--------" << "------+---" << "--------" << '\n'
for(numRabbits=0 ; numRabbits<=(totalFeet/4) ; numRabbits++) {
if(checkSolution = true){
numChicken=(totalFeet-4*numRabbits)/2;
cout << setw(8) << numRabbits << " | " << setw(8) << numChicken << '\n'
}
}
cout << '\n'
system("pause");
}
這樣應該OK了吧