water-bottles.cpp (800B)
1 #include <iostream> 2 using namespace std; 3 4 5 6 //Leet Ratings 7 // Speed Memory 8 //Total 0ms 5.9MB 9 //Beats 100% 61.85% 10 11 12 13 int numWaterBottles(int numBottles, int numExchange) { 14 15 //numBottles is used to track the number of empty bottles 16 //given that all bottles are drank right at the beginning. 17 int num_drank = numBottles; 18 while(numBottles >= numExchange){ 19 num_drank += 1; 20 numBottles += 1; 21 numBottles = numBottles - numExchange; 22 } 23 return num_drank; 24 } 25 26 27 int main(){ 28 cout << "Number of Bottles To Start: "; 29 int bottles_start = 0; 30 int bottles_exchange = 0; 31 cin >> bottles_start; 32 cout << "Number of Bottles To Exchange: "; 33 cin >> bottles_exchange; 34 cout << numWaterBottles(bottles_start, bottles_exchange) << endl; 35 }