/* chessPence-short.cpp written by Kevin Corcoran CIS 122, Week 7 lab This program takes an integer input and calculates the number of pennies on this square and the entire chessboard assuming exponential increase in penny placement. */ #include #include using namespace std; int main(){ // How many sqaure shall we consider? int squares; // The number of pennies on the current square int term; // The total number of pennies on the chessboard, // up to an including this square int sumTerm = 0; // Prompt user for input cout << "Enter a square on the chess board: "; cin >> squares; bool tooBig = squares > 64; if(tooBig) cout << "\nThere are not that many squares on the chessboard!" << endl; else{ for(int i = 0; i < squares; i++){ // Calculate the number of pennies on this square term = pow(2.0, i); // Add the current number of pennies to the total # of pennies sumTerm = sumTerm + term; } // Output results cout << "\nSquare #" << squares << " has " << term << " pennies on it." << endl << "There are " << sumTerm << " total pennies on the chess board." << endl; } return 0; }