Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,221 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 984 people online right now. Registration is fast and FREE... Join Now!




Looping program

 
Reply to this topicStart new topic

Looping program, problems, not sure what errors mean

tatertot560
post 13 Mar, 2008 - 09:21 PM
Post #1


New D.I.C Head

*
Joined: 4 Mar, 2008
Posts: 8

im still pretty new to c++ and for this program, i use loops, but i don't think i wrote them correctly. i keep running into errors. i really don't understand what they mean, so if someone can help me comprehend, i would really appreciate it!
my program and the errors:

CODE


//This assignment5.cpp program is designed to read from an input file
// and compute the costs for the Green Tree Service Company.  The input
//file include data that represents a series of jobs that the company
//has performed.  Using the data values, it will compute the amount
//of each job.  It will list each job as a character with integers and
//float values if applicable.  It will also generate a statement that
//lists each job and the job number.  it will also include the following
//computed amounts: tree planting, tree removal, tree trimming, stump
//removal, total billed and the total amount due.


//Input:  the input will be read from a data file.  No input will be
//entered by the user.
//Output: the output will display a nicely formatted statement that
//displays the amounts two decimal points to the right, and will be
//right-justified.  The amounts displayed will be: tree planting,tree
//removal, trimming, stump removal, total billed, and the TOTAL.

#include <iostream>
#include <iomanip>
using namespace std;

const float SMALLTREE = 35.00; // cost of planting small tree
const float MEDTREE = 100.00; // cost of planting medium tree
const float LARGETREE = 500.00; // cost of planting large tree
const float TREEREMOVAL = 500.00; // cost of tree removal
const float HRTRIMMING = 75.00; // cost of trimming per hour
const float STUMPREM1 = 75.00; // cost of removing stump diameter < 10 inches
const float STUMPREM2 = 10.00; // cost of removing stump diameter > 10 inches

int main()
{
   int num;
   int numoftrees;
   int numoftrees2;
   int largetreeamt;
   int numremove;
   int diameter1;
   int diameter2;
   int jobnum;
   int counter;
   float trimhrs;
   float smalltreeamt;
   float medtreeamt;
   float trimminghrs;
   float removalamt1;
   float removalamt2;
   float TOTAL;

   cout << fixed << showpoint << setprecision(2);

   {
     int numoftrees1;
     cin >> numoftrees1;
     for ( int i=0; i < numoftrees1; i++)
       {
         smalltreeamt = 0;
         for (int j=0; j<numoftrees1; j++)
           {
             cin >> numoftrees1;
             smalltreeamt = SMALLTREE * numoftrees1;
           }
         cout << smalltreeamt << endl;
       }

     {
       int numoftrees2;
       cin >> numoftrees2;
       for (int i=0; i < numoftrees2; i++)
         {
           medtreeamt = 0;
           for (int j=0; j<num; j++)
             {
               cin >> numoftrees2;
               medtreeamt = MEDTREE * numoftrees2;
             }
           cout << medtreeamt << endl;
         }


       {
         int numoftrees3;
         cin >> numoftrees3;
         for ( int i = 0; i < numoftrees3; i++)
           {
             largetreeamt = 0;
             for (float j=0; j<num; j++)
               {
                 cin >> numoftrees3;
                 largetreeamt = SMALLTREE * numoftrees3;
               }
             cout << largetreeamt << endl;
           }

         {
           float removalamt;
           int numremove;
           cin >> removalamt;
           for (int i = 0; i < numremove; i++)
             {
               cin >> numremove;
               removalamt = TREEREMOVAL * numremove;
             }
           cout <<  removalamt << endl;
         }

         {
           int sum = 0;
           float trimhours;
           int count;
           cin >> trimhours;
           for ( int i = 0; i < count; i++)
             {
               cin >> trimhours;
               trimminghrs = HRTRIMMING * trimhours;
                 }
           cout << trimminghrs << endl;
         }

         int diameter1;
         cin >> diameter1;
         for ( int i = 0; i < diameter1; i++)
           {
             if (diameter1 <= 10)
               {
                 cin >> diameter1;
                 removalamt1 = STUMPREM1 * diameter1;
               }
             else (diameter2 > 10);
               {
                 cin >> diameter2;
                 removalamt2 = STUMPREM2 * diameter2;
                   }
           }

         cin >> jobnum;

         int cnt = 0, sum = 0, data;
         float smalltreeamt;
         float medtreeamt;
         float largetreeamt;
         float removalamt;
         float trimminghrs;
         float removalamt1;
         float removalamt2;
         float TOTAL;


           cin >> data;
         while (!cin.eof())
             {
               TOTAL = smalltreeamt + medtreeamt + largetreeamt +
               removalamt + trimminghrs + removalamt1 + removalamt2;
                 cout << TOTAL << endl;

             }


         {
           cin >> jobnum;

           cout << setw(23) << setfill(' ') << setw(20) << left << "Tree"
                << setw(20) << setfill(' ') << left << setw(11)
                << "Stump" << setw(7) << "Total" << endl;
           cout << left << setw(8) << "Job #" << left << setw(14)            << "Planting"
                << left << setw(11) << "Trimming" << left << setw(11)
                << "Removal" << left << setw(8) << "Billed" << endl;
           cout << left << setw(8) << jobnum << "$" << setw(9) << right
                << numoftrees << setw(3) << "$" << setw(9) << right
                << removalamt << setw(3) << "$" << setw(9) << right
                << trimminghrs << setw(3) << "$" << setw(9) << right
                << removalamt1 || removalamt2 << setw(3) << right << TOTAL
                << endl;
           cout << setw(57) << "TOTAL" << "$" << setw(9) << TOTAL <<endl;


         return 0;
         }}}}

         }



and these are the errors i get:

assignment5.cpp: In function âint main()â:
assignment5.cpp:69: error: name lookup of âiâ changed for new ISO âforâ scoping
assignment5.cpp:55: error: using obsolete binding at âiâ
assignment5.cpp:90: warning: converting to âintâ from âfloatâ
assignment5.cpp:172: error: no match for âoperator<<â in âremovalamt2 << std::setw(3)â


again, thanks for anyone who can explain/kind of help me smile.gif

This post has been edited by tatertot560: 14 Mar, 2008 - 07:55 AM
User is offlineProfile CardPM

Go to the top of the page

Glasseater
post 13 Mar, 2008 - 09:32 PM
Post #2


New D.I.C Head

*
Joined: 15 Jun, 2007
Posts: 46


My Contributions


Well for most of your errors your for loops seems to be really messed up.

This is what you have for the first one
CODE
for ( numoftrees2=0; i < num; i++)


I think what you want is
CODE
for ( int i = 0; i < numoftrees2; i++)

for ( counter ; condition ; increment )

And the last error, just replace || with << on line 172

You can ignore the warning about conversion for now.
User is offlineProfile CardPM

Go to the top of the page

tatertot560
post 13 Mar, 2008 - 10:03 PM
Post #3


New D.I.C Head

*
Joined: 4 Mar, 2008
Posts: 8

QUOTE(Glasseater @ 13 Mar, 2008 - 10:32 PM) *

Well for most of your errors your for loops seems to be really messed up.

This is what you have for the first one
CODE
for ( numoftrees2=0; i < num; i++)


I think what you want is
CODE
for ( int i = 0; i < numoftrees2; i++)

for ( counter ; condition ; increment )

And the last error, just replace || with << on line 172

You can ignore the warning about conversion for now.


i did what you suggested and it worked. but now i have these errors:


assignment5.cpp:69: error: expected unqualified-id before â=â token
assignment5.cpp:69: error: name lookup of âiâ changed for new ISO âforâ scoping
assignment5.cpp:55: error: using obsolete binding at âiâ
assignment5.cpp:90: warning: converting to âintâ from âfloatâ

do i have to rewrite those parts of the program? thx
User is offlineProfile CardPM

Go to the top of the page

captainhampton
post 14 Mar, 2008 - 06:51 AM
Post #4


Jawsome++;

Group Icon
Joined: 17 Oct, 2007
Posts: 518



Thanked 2 times

Dream Kudos: 825
My Contributions


[quote name='tatertot560' date='13 Mar, 2008 - 11:03 PM' post='325648']
[quote name='Glasseater' post='325639' date='13 Mar, 2008 - 10:32 PM']

assignment5.cpp:90: warning: converting to âintâ from âfloatâ

do i have to rewrite those parts of the program? thx
[/quote]

Keep in mind that you must stay consistent with your declarations, if you are using ints and floats to attempt to get the same data you need to either keep it of the same data type or perform a type coercian of the particular type
User is offlineProfile CardPM

Go to the top of the page

Glasseater
post 14 Mar, 2008 - 08:58 AM
Post #5


New D.I.C Head

*
Joined: 15 Jun, 2007
Posts: 46


My Contributions


I get no errors when I compile the program. I do get a ton of warnings though.

I suggest you go through your program and clean it up a bit. You have a lot of variables going in and out of scope. You could be calling a variable that no longer exists. I suggest removing as many of those scopes as possible.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/21/08 08:52PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month