# include # include using namespace std; int main ( ) // // TRUCK_FOR uses a FOR loop to search DOWN for the maximum number of // bricks a truck can carry across s bridge with a weight limit of LIMIT pounds. // // We also use a BREAK statement to jump out of the FOR loop if a // solution is found. // { int bricks; int limit; int solution; int truck; limit = 3000; truck = 2000; solution = -1; for ( bricks = 1000; 0 <= bricks; bricks-- ) { if ( truck + 5 * bricks <= limit ) { solution = bricks; break; } } cout << "The bridge limit is " << limit << " pounds.\n"; cout << "The truck weighs " << truck << " pounds.\n"; if ( solution == -1 ) { cout << "No solution was found.\n"; } else { cout << "The truck can cross with " << solution << " bricks.\n"; } return 0; }