### counting loops

I need to put it as so i can count how many loops happend. I need to keep using the formula "totalAmount = amount + (amount * rate)" until i get a number that is more or equal to 5000. But i also need to count how many times it looped, how am i supposed to do that. I know that i am supposed to use while and counter, but how do i put it together?

*Note: I did not finish program.

 ``12345678910111213141516171819202122232425262728293031323334`` ``````/* Program: \$5,000.00 or more Date: 12/14/13 Description: This programs calculates when it will take for money to become \$5,000.00 or greater. */ #include #include #include using namespace std; int main() { // Declaration of Variables and Constants double totalAmount; double amount; double rate = 0.075; // Input cout << "Enter amount of money you are investing: "; cin >> amount; totalAmount = amount + (amount * rate) // Process and Output if (totalAmount < 5000) { while (totalAmount < 5000) { totalAmount = amount + (amount * rate)``````
 ``123456789101112131415161718192021222324252627282930313233343536373839`` ``````/* Program: \$5,000.00 or more Date: 12/14/13 Description: This programs calculates when it will take for money to become \$5,000.00 or greater. */ #include #include #include using namespace std; int main() { // Declaration of Variables and Constants double totalAmount; double amount; double rate = 0.075; int counter=0; // Input cout << "Enter amount of money you are investing: "; cin >> amount; totalAmount = amount + (amount * rate) // Process and Output if (totalAmount < 5000) { while (totalAmount < 5000) { totalAmount = amount + (amount * rate) counter++; } } cout<
Last edited on
Topic archived. No new replies allowed.