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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*  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 <cstdlib>
#include <iostream>
#include <string>

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)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*  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 <cstdlib>
#include <iostream>
#include <string>

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<<counter;
Last edited on
Topic archived. No new replies allowed.