# include # include using namespace std; int main ( ) // // A bridge was a weight limit of LIMIT pounds. // // A truck weighs 2000 pounds, and is carrying 1000 5 pound bricks. // How many bricks can the truck carry over the bridge? { int bricks; int limit; int truck; cout << "Enter the weight limit on the bridge: "; cin >> limit; cout << "The bridge limit is " << limit << " pounds.\n"; truck = 2000; bricks = 1000; while ( limit < truck + 5 * bricks ) { bricks = bricks - 1; // // Once we have reached 0 bricks, we shouldn't try to // go any lower! // if ( bricks < 0 ) { cerr << "\n"; cerr << "The truck cannot cross!\n"; exit ( 1 ); } } cout << "Truck made the limit with " << bricks << " bricks.\n"; cout << "Truck + bricks = " << truck + 5 * bricks << " pounds.\n"; return 0; }