do while loop?

Noob alert! I am learning C++ through an online class and a Dummies book. I am unsure if I should be using a do while loop for my program. I have to put in a value for "a" and it will compute how long it will take for it to become something else (x) at a rate of 2%. Should this be a do while loop or a for loop?...or something entirely else. Here's what I have so far:

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
/*------------------------------------------------------------------------------------------------------------------------*/
/*	Write a program to determine how many years are required for the # of acres to be completely reforestation            */
     
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
	// Declare and initialize objects.
	double a;	// acres of reforestation.
	double x;	// time it took for reforestation.
	
	do
	{
	cout << "Number of acres to determine \n";
	cin >> a;

	x = ((a+.02)*100);
	
	} while (a>0; ++a);

cout << x << "Number of years for acres to be reforested"<< endl;


// Wait to close the program.
	system ("PAUSE");
	return 0;
}
/*-------------------------------------------------------------------------------------------------------------------------*/
Your program does not compile.
I suggest you to use the tutorials and learn the syntax http://cplusplus.com/doc/tutorial/control/
The only difference is that do-while loop is executed at least one time.
Then understand that it is while and not until

Your code makes little sense. Make a desk test.

Dummies book
I'd heard bad critics about that book.
system ("PAUSE"); is one of them.
I have modified my code and it runs but doesn't do anything. Thoughts?


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
/*----------------------------------------------------------------------------------------------------------*/
/*	Write a program to determine how many years are required for the # of acres to be reforested            */
     
#include <iostream>
#include <iomanip>
#include <string> 

using namespace std;

int main()
{
	// Declare and initialize objects.
	double acre;	// acres of reforestation.
	double forest;	// time it took for reforestation.
	
	//Prompt user for input.
	cout << "Please enter the numbers of acres to be reforested \n";

	//Input of number of acres.
	cin >> acre;
	while (acre > 0);
	
	{
	forest = ((acre+.02)*100);
	cin >> acre;
	}

	cout << "Number of years for reforestation is \n" << endl;
	
// Wait to close the program.
	system ("PAUSE");
	return 0;
}
/*-------------------------------------------------------------------------------------------------------------------------*/
It's waiting for input. ¿what input? beats me.

Make a desk test and tell me what do you think that your program is doing
Topic archived. No new replies allowed.