Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > dev c++ help

dev c++ help
Thread Tools
Fresh-Faced Recruit
Join Date: Jul 2005
Status: Offline
Reply With Quote
Jul 20, 2005, 06:28 PM
 
I am very new at c++ and need some help
here is the question:
Assume that there are 14000 acres total with 2500 acres uncut and that the reforestation rate is .02. Print a table showing the numbers of acres forested at the end of each year for a total of 20 years.
here is what I have so far:

#include <iostream>
#include <stdlib.h>
using namespace std;

int main()
{
//declare variables
int year;
double clear, forested, totalforested, growth;


//calculate the growth conversion


//write the table
cout << "Table showing the the number of acres"
" forested each year over 20 years" << endl
<< "Year \t\t Forested Acres" << endl << endl;

//write the loop
for (year = 1; year <= 20; year++)
{
//clear = 11500;
//forested = 2500;
totalforested = (clear * .02) + forested
(clear * .02) = growth
growth + forested = totalforested
clear - growth = clear
forested = totalforested

cout << year << totalforested << endl;

}

system("PAUSE");
return 0;
}


It is returning an error on line 31: forested cannot be used as a function
and on line 32: expected ';' before "growth"
any help is appreciated
thanks
     
Fresh-Faced Recruit
Join Date: Jul 2005
Status: Offline
Reply With Quote
Jul 20, 2005, 06:45 PM
 
nevermind, i figured it out. somehow
     
Mac Enthusiast
Join Date: Nov 2003
Status: Offline
Reply With Quote
Jul 21, 2005, 07:59 AM
 
Originally Posted by dgrooman
nevermind, i figured it out. somehow
You forgot to end your line (and a few other lines) with a semicolon, so the compiler interpreted "forested" as a function:

Code:
totalforested = (clear * .02) + forested (clear * .02) = growth
was read as:

Code:
totalforested = (clear * .02) + forested(clear * .02) = growth
Since white space isn't important in C/C++, you have to use semicolons to end every statement.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:22 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2