Mac C++ and XCode Help

FireflyMal

macrumors newbie
Original poster
Mar 19, 2012
8
0
Hello,

I am new to programming and am taking an intro class. I am having trouble with XCode and getting my code to compile with multiple files. I am using headers, but I keep receiving the following errors.

On consoleUI.cpp, I get 2 errors:
1. No previous prototype for function "consoleUI"
2. No matching function for call "PaintJobEstimator"

On PaintJobEstimator.cpp, I get 1 error:
1. No previous prototype for function "PaintJobEstimator"


If anyone could help, I would be grateful. Thank you. Below is my code. I can't even compile to test if the logic works.


main.cpp:
Code:
#include <iostream>

// Include Header file
#include "consoleUI.h"

using namespace std;

    
void consoleUI();

int main()
{
    
    consoleUI();
    
    return 0;
}
consoleUI.cpp:
Code:
#include <iostream>
#include <iomanip>

// Include Header File
#include "PaintJobEstimator.h"


using namespace std;



// Begin Console UI
void consoleUI ()
{
        
    int rooms = 0;              // Number of Rooms
    int cnt = 0;                // Counter for rooms
    double paint = 0.00;        // Number of gallons of paint
    double ceilPaint = 0.00;    // Paint rounded up
    double labor = 0.00;        // Labor hours needed
    double sqft = 0.00;         // Square footage of wall
    double laborCost = 0.00;    // Cost of labor
    double paintCost = 0.00;    // Cost of paint
    double priceOfPaint = 0.00; // Price of paint * paintCost
    double totalCost = 0.00;    // Total Cost
    bool isValid = false;       // Loop validation

    
    // Input for rooms
    cout<<"How many rooms would you like to paint?\n";
    cin>>rooms;
    cout<<"You entered: "<<rooms <<" rooms.\n";
    
    // Input for Paint Cost
    cout<<"What is the price of paint per gallon?\n";
    cin>>paintCost;
    
    
    // Input validation loop
    while (! isValid)
    {
        
        // Loop for calculation of each room
        for (cnt=0; cnt<=rooms; cnt--)
        {
            
            if (rooms > 0 && rooms <= 25)
            {
                cout<<"What is the total square footage for the walls of the entire room?\n";
                cin>>sqft;
                
                sqft += sqft;
                    
                
                if (sqft > 0.00)
                {                    
                    if (paintCost >= 10.00)
                    {
                        isValid = true;
                    }                    
                }                
            } 
            
            else
            {
                cout<<"Invalid entry.\n";
            }
            
        }
                    
    }
    
    // Call function to compute costs
    PaintJobEstimator (paint, labor, sqft, paintCost, laborCost, priceOfPaint); 
    
    
    // Output Costs    
    cout << fixed << setprecision(2);
    cout <<"Number of gallons of paint: " << ceilPaint <<endl;
    cout <<"Hours of labor: " << labor <<endl;
    cout <<"Cost of paint: $"<< setw(7) << paintCost <<endl;
    cout <<"Labor charge: $"<< setw(7) << laborCost <<endl;
    cout <<"Total cost: $"<< setw(7) << totalCost <<endl;
    
    
}
PaintJobEstimator.cpp:
Code:
#include <stdio.h>
#include <math.h>
#include <cmath>

double PaintJobEstimator (double& ceilPaint, double& paint, double& labor, double& sqft, double& paintCost, double& laborCost, double& priceOfPaint, double& totalCost)
{
    // Ceiling Function for gallons of paint    
    ceilPaint = sqft/115;
    paint = ceil (ceilPaint);
    
    // Cost of labor, paint & total costs
    labor = ((sqft/115) * 8);
    laborCost = labor * 18.00;
    priceOfPaint = paint * paintCost;
    totalCost = laborCost + priceOfPaint;
    
    return 0;
}
consoleUI.h:
Code:
#ifndef Paint_Job_Estimator_consoleUI_h
#define Paint_Job_Estimator_consoleUI_h

void consoleUI ();

#endif
PaintJobEstimator.h:
Code:
#ifndef Paint_Job_Estimator_PaintJobEstimator_h
#define Paint_Job_Estimator_PaintJobEstimator_h

double PaintJobEstimator (double& ceilPaint, double& paint, double& labor, double& sqft, double& paintCost, double& laborCost, double& priceOfPaint, double& totalCost);

#endif
 

gnasher729

macrumors P6
Nov 25, 2005
16,568
3,148
Hello,

I am new to programming and am taking an intro class. I am having trouble with XCode and getting my code to compile with multiple files. I am using headers, but I keep receiving the following errors.

On consoleUI.cpp, I get 2 errors:
1. No previous prototype for function "consoleUI"
2. No matching function for call "PaintJobEstimator"

On PaintJobEstimator.cpp, I get 1 error:
1. No previous prototype for function "PaintJobEstimator"
A source file like PaintJobEstimator.cpp would include PaintJobEstimator.h unless you have a very very good reason not to. Same for consoleUI.cpp and consoleUI.h.

Next, compare the call to PaintJobEstimator and the actual function very, very carefully.
 

FireflyMal

macrumors newbie
Original poster
Mar 19, 2012
8
0
Thank you! Doing the #include worked for the errors. Now I have to fix my code. There's an infinite loop in there, and no check for invalid entries for square footage.

I also guess I don't have an understanding of references as I thought.

Gnasher, I appreciate your help. Thank you!
 

chrono1081

macrumors 604
Jan 26, 2008
7,525
1,492
Isla Nublar
So does this function:

Code:
double PaintJobEstimator (double& ceilPaint, double& paint, double& labor, double& sqft, double& paintCost, double& laborCost, double& priceOfPaint, double& totalCost)
{
    // Ceiling Function for gallons of paint    
    ceilPaint = sqft/115;
    paint = ceil (ceilPaint);
    
    // Cost of labor, paint & total costs
    labor = ((sqft/115) * 8);
    laborCost = labor * 18.00;
    priceOfPaint = paint * paintCost;
    totalCost = laborCost + priceOfPaint;
    
    [B]return 0;[/B]
}
The function is set up as a value returning function, but in your code you call it like a void function with this line:

Code:
  // Call function to compute costs
    PaintJobEstimator (paint, labor, sqft, paintCost, laborCost, priceOfPaint);
Honestly I'm not sure how it compiles :confused::confused::confused:


EDIT: Ooops I see Gnasher already mentioned it in a previous post :D
 

FireflyMal

macrumors newbie
Original poster
Mar 19, 2012
8
0
Ok, I think I've got it, but I am having trouble with compounding the values entered for sqft. For some reason, it is not compounding it correctly. I'm not exactly sure what it's doing.

Again, thanks for the help everyone. It's awesome to have a Mac programming community that is helpful for beginners like myself!

main.cpp:
Code:
#include <iostream>

// Include Header file
#include "consoleUI.h"

    
void consoleUI();

int main()
{
    
    consoleUI();
    
    return 0;
}
consoleUI.cpp
Code:
#include <iostream>
#include <iomanip>

// Include Header File
#include "PaintJobEstimator.h"
#include "consoleUI.h"

using namespace std;



// Begin Console UI
void consoleUI ()
{
        
    int rooms = 0;              // Number of Rooms
    int cnt = 0;                // Counter for rooms
    double ceilPaint = 0.00;    // Number of gallons of paint rounded up
    double labor = 0.00;        // Labor hours needed
    double sqft = 0.00;         // Square footage of wall
    double laborCost = 0.00;    // Cost of labor
    double paintCost = 0.00;    // Cost of paint
    double priceOfPaint = 0.00; // Price of paint * paintCost
    double totalCost = 0.00;    // Total Cost
    bool isValid = false;       // Loop validation
    bool sqftValid = false;     // Loop validation for square footage
    bool paintValid = false;    // Loop validation for paint cost

    
    
    // Input validation loop
    while (! isValid)
    {
        
        // Input for rooms
        cout<<"How many rooms would you like to paint?\n";
        cin>>rooms;
        cout<<"You entered: "<<rooms <<" rooms.\n\n";
        
            if (rooms > 0)
            {    
                // Validation loop for paint cost
                while (!paintValid)
                {
                   
                    // Input for Paint Cost
                    cout<<"What is the price of paint per gallon?\n";
                    cin>>paintCost;
                    cout<<"You entered " <<paintCost <<"\n\n";
        
                        // Control Statement to determine if for loop will run
                        if (paintCost >= 10.00)
                        {
                            paintValid = true;
                            isValid = true;
                            
                                // Square footage validation loop
                                while (! sqftValid)
                                {
                                    cout<<"What is the total square footage for the walls of the entire room?\n";
                                    cin>>sqft;
                                
                                        if (sqft > 0.00)
                                        {                     
                                            sqftValid = true;                 
                                
                                
                                            // Loop for calculation of each room
                                            for (cnt=(rooms-1); cnt>0; cnt--)
                                            {
                                                cout<<"For the next room, what is the total square footage for the walls of the entire room?\n";
                                                cin>>sqft;
                                                sqft += sqft;
                                            }
                                        }
                                        else
                                        {
                                            cout <<"That is not a valid entry for square footage. Please enter a valid square footage.\n";
                                        }
                                }
                        
                        }
                        else
                        {
                            cout <<"Invalid entry for cost of paint. Must be higher than $10\n\n";
                        }
                }

                        
                
            }
            else
            {            
                cout<<"Invalid Entry for rooms.\n";
            }                    
    }
    
    // Call function to compute costs and output Costs 
    PaintJobEstimator(ceilPaint, labor, sqft, paintCost, laborCost, priceOfPaint, totalCost);
    cout << fixed << setprecision(2);
    cout <<"Gallons of paint:   " << setw(7) << ceilPaint <<endl;
    cout <<"Hours of labor:     " << setw(7) << labor <<endl;
    cout <<"Cost of paint:     $" << setw(7) << priceOfPaint <<endl;
    cout <<"Labor charge:      $" << setw(7) << laborCost <<endl;
    cout <<"Total cost:        $" << setw(7) << totalCost <<endl;
    
    
}
PaintJobEstimator.cpp
Code:
#include <stdio.h>
#include <math.h>
#include <cmath>
#include "PaintJobEstimator.h"

double PaintJobEstimator (double& ceilPaint, double& labor, double& sqft, double& paintCost, double& laborCost, double& priceOfPaint, double& totalCost)
{
    // Ceiling Function to round up for gallons of paint
    ceilPaint = sqft/115;
    ceilPaint = ceil (ceilPaint);
    
    // Cost of labor, paint & total costs
    labor = ((sqft/115) * 8);
    laborCost = labor * 18.00;
    priceOfPaint = ceilPaint * paintCost;
    totalCost = laborCost + priceOfPaint;
    
    return 0;
}
consoleUI.h
Code:
#ifndef Paint_Job_Estimator_consoleUI_h
#define Paint_Job_Estimator_consoleUI_h

void consoleUI ();

#endif
PaintJobEstimator.h
Code:
#ifndef Paint_Job_Estimator_PaintJobEstimator_h
#define Paint_Job_Estimator_PaintJobEstimator_h

double PaintJobEstimator (double& ceilPaint, double& labor, double& sqft, double& paintCost, double& laborCost, double& priceOfPaint, double& totalCost);

#endif


----------

So does this function:

Code:
double PaintJobEstimator (double& ceilPaint, double& paint, double& labor, double& sqft, double& paintCost, double& laborCost, double& priceOfPaint, double& totalCost)
{
    // Ceiling Function for gallons of paint    
    ceilPaint = sqft/115;
    paint = ceil (ceilPaint);
    
    // Cost of labor, paint & total costs
    labor = ((sqft/115) * 8);
    laborCost = labor * 18.00;
    priceOfPaint = paint * paintCost;
    totalCost = laborCost + priceOfPaint;
    
    [B]return 0;[/B]
}
The function is set up as a value returning function, but in your code you call it like a void function with this line:

Code:
  // Call function to compute costs
    PaintJobEstimator (paint, labor, sqft, paintCost, laborCost, priceOfPaint);
Honestly I'm not sure how it compiles :confused::confused::confused:


EDIT: Ooops I see Gnasher already mentioned it in a previous post :D
My thought process here was to call the function at the end to perform all of the math. Then, I would output the results for the user to see. The code compiles, however I have an issue with compounding the sqft. It's not compounding correctly.
 

chown33

Moderator
Staff member
Aug 9, 2009
8,486
4,495
Restivus
main.cpp:
Code:
// Square footage validation loop
while (! sqftValid)
{
    cout<<"What is the total square footage for the walls of the entire room?\n";
    cin>>sqft;

        if (sqft > 0.00)
        {                     
            sqftValid = true;                 


            // Loop for calculation of each room
            for (cnt=(rooms-1); cnt>0; cnt--)
            {
                cout<<"For the next room, what is the total square footage for the walls of the entire room?\n";
[COLOR="Red"]                cin>>sqft;
                sqft += sqft;
[/COLOR]
             }
        }
        else
        {
            cout <<"That is not a valid entry for square footage. Please enter a valid square footage.\n";
        }
}
The code compiles, however I have an issue with compounding the sqft. It's not compounding correctly.
If by "compounding" you mean the red-hilited code, I urge you to walk through this loop manually, using pencil and paper if necessary. Show your work at each iteration. That is, write out the values of the affected variables at each statement of each iteration. Is this what you expected to happen?

Or learn to use the debugger to step through loops like this, observing variables.

The important thing is that you visualize what actually happens. Not what you thought would happen when you wrote it, but what actually happens when the algorithm executes. This loop is simple enough that you ought to be able to do it manually. An experienced programmer should be able to visualize this loop in their head. You will too after you see what's wrong with it.
 

chrono1081

macrumors 604
Jan 26, 2008
7,525
1,492
Isla Nublar
...snip...
My thought process here was to call the function at the end to perform all of the math. Then, I would output the results for the user to see. The code compiles, however I have an issue with compounding the sqft. It's not compounding correctly.
Well, first lets address the function mentioned. Apologies in advance if you understand the concept but just in case you don't here it is:

There are two types of functions, void functions and value returning functions.

A void function will look like this:

Code:
void AddNumbers(int a, int b)
{

int c = a + b;
cout << "The numbers added are: "<< c << endl;
}
To call this function you would just simply say:

Code:
AddNumbers(4, 5);
and the console would output 9 because the void function is printing straight to the console and not relying on another part of the program to do that for it.

Now, your function is declared as a value returning function which looks similar this:

Code:
double AddNumbers(double a, double b)
{
return a + b; //Your function has 0 instead of a value
}
This means your function is expected to return a value of type "double".

To use it, you have to use it in a way that the result can be used (or in your case, printed out to the screen).

Something like this would work:

Code:
cout << "10 + 5 = " << AddNumbers(10,5) << endl;

//Note: Its generally good programming practice to write a decimal after floats and doubles for clarity, like
//AddNumbers(10.0, 5.0) but I omitted them.
You could also do it like this:

Code:
double c = AddNumbers(10,5);
cout << "c = " << c << endl;

Notice how in your code you have this function:

Code:
double PaintJobEstimator (double& ceilPaint, double& labor, double& sqft, double& paintCost, double& laborCost, double& priceOfPaint, double& totalCost)
{
    // Ceiling Function to round up for gallons of paint
    ceilPaint = sqft/115;
    ceilPaint = ceil (ceilPaint);
    
    // Cost of labor, paint & total costs
    labor = ((sqft/115) * 8);
    laborCost = labor * 18.00;
    priceOfPaint = ceilPaint * paintCost;
    totalCost = laborCost + priceOfPaint;
    
    return 0; //This should return totalCost, not zero. 
}
You declared the function as type double, meaning its a value returning function and should return a double. While 0 is a perfectly valid value to return its not going to give you the result you wanted.

When you call this function in this line:

Code:
PaintJobEstimator(ceilPaint, labor, sqft, paintCost, laborCost, priceOfPaint, totalCost);
It doesn't do anything because there is no where for it to output its results. If you want to show the total cost on the screen, do something like this:

Code:
cout << "This is the total cost of the paint job: " << PaintJobEstimator(ceilPaint, labor, sqft, paintCost, laborCost, priceOfPaint, totalCost) << endl;
I know that was wordy and lengthy but do you understand the difference between void and value returning functions? If not maybe someone can explain better than I can. It's insanely important that you grasp this concept early on.
 
Last edited:

FireflyMal

macrumors newbie
Original poster
Mar 19, 2012
8
0
If by "compounding" you mean the red-hilited code, I urge you to walk through this loop manually, using pencil and paper if necessary. Show your work at each iteration. That is, write out the values of the affected variables at each statement of each iteration. Is this what you expected to happen?

Or learn to use the debugger to step through loops like this, observing variables.

The important thing is that you visualize what actually happens. Not what you thought would happen when you wrote it, but what actually happens when the algorithm executes. This loop is simple enough that you ought to be able to do it manually. An experienced programmer should be able to visualize this loop in their head. You will too after you see what's wrong with it.
Thank you for telling me to write this out. After doing this, I found my error. That helped me visualize it step by step.

Here is the fixed code. It is now working as intended!
Code:
// Square footage validation loop
                                while (! sqftValid)
                                {
                                    cout<<"What is the total square footage for the walls of the entire room?\n";
                                    cin>>sqft;
                                    totalSqft = totalSqft + sqft;
                                    
                                        if (sqft > 0.00)
                                        {                     
                                            sqftValid = true;                 
                                
                                
                                            // Loop for calculation of each room
                                            for (cnt=(rooms-1); cnt>0; cnt--)
                                            {
                                                cout<<"For the next room, what is the total square footage for the walls of the entire room?\n";
                                                cin>>sqft;
                                                totalSqft = totalSqft + sqft;
                                            }


----------

Well, first lets address the function mentioned. Apologies in advance if you understand the concept but just in case you don't here it is:

There are two types of functions, void functions and value returning functions.

A void function will look like this:

Code:
void AddNumbers(int a, int b)
{

int c = a + b;
cout << "The numbers added are: "<< c << endl;
}
To call this function you would just simply say:

Code:
AddNumbers(4, 5);
and the console would output 9 because the void function is printing straight to the console and not relying on another part of the program to do that for it.

Now, your function is declared as a value returning function which looks similar this:

Code:
double AddNumbers(double a, double b)
{
return a + b; //Your function has 0 instead of a value
}
This means your function is expected to return a value of type "double".

To use it, you have to use it in a way that the result can be used (or in your case, printed out to the screen).

Something like this would work:

Code:
cout << "10 + 5 = " << AddNumbers(10,5) << endl;

//Note: Its generally good programming practice to write a decimal after floats and doubles for clarity, like
//AddNumbers(10.0, 5.0) but I omitted them.
You could also do it like this:

Code:
double c = AddNumbers(10,5);
cout << "c = " << c << endl;

Notice how in your code you have this function:

Code:
double PaintJobEstimator (double& ceilPaint, double& labor, double& sqft, double& paintCost, double& laborCost, double& priceOfPaint, double& totalCost)
{
    // Ceiling Function to round up for gallons of paint
    ceilPaint = sqft/115;
    ceilPaint = ceil (ceilPaint);
    
    // Cost of labor, paint & total costs
    labor = ((sqft/115) * 8);
    laborCost = labor * 18.00;
    priceOfPaint = ceilPaint * paintCost;
    totalCost = laborCost + priceOfPaint;
    
    return 0; //This should return totalCost, not zero. 
}
You declared the function as type double, meaning its a value returning function and should return a double. While 0 is a perfectly valid value to return its not going to give you the result you wanted.

When you call this function in this line:

Code:
PaintJobEstimator(ceilPaint, labor, sqft, paintCost, laborCost, priceOfPaint, totalCost);
It doesn't do anything because there is no where for it to output its results. If you want to show the total cost on the screen, do something like this:

Code:
cout << "This is the total cost of the paint job: " << PaintJobEstimator(ceilPaint, labor, sqft, paintCost, laborCost, priceOfPaint, totalCost) << endl;
I know that was wordy and lengthy but do you understand the difference between void and value returning functions? If not maybe someone can explain better than I can. It's insanely important that you grasp this concept early on.
Ok, I thought I had understood this, but you clarified this for me a bit better. Since I am only using this function to perform math and don't care about this function returning a value, I have now set it to void. It now works exactly as I want it to.

My new code is:
Code:
#include <stdio.h>
#include <math.h>
#include <cmath>
#include "PaintJobEstimator.h"

void PaintJobEstimator (double& ceilPaint, double& labor, double& totalSqft, double& paintCost, double& laborCost, double& priceOfPaint, double& totalCost)
{
    // Ceiling Function to round up for gallons of paint
    ceilPaint = totalSqft/115;
    ceilPaint = ceil (ceilPaint);
    
    // Cost of labor, paint & total costs
    labor = ((totalSqft/115) * 8);
    laborCost = labor * 18.00;
    priceOfPaint = ceilPaint * paintCost;
    totalCost = laborCost + priceOfPaint;
    
}

Thanks everyone for the help with this! I'm still very new to this (first semester of programming).
 

chrono1081

macrumors 604
Jan 26, 2008
7,525
1,492
Isla Nublar
Oh crap I didn't catch that you were using references.

No matter though, its better as a void function since having a double returning 0 is kind of confusing to anyone using the function since they can't use it as part of an equation or something.

Also great news that it is now working for you. One thing to definitely learn early on (if you don't know how to do it already) is to learn to use the debugger to check variable values. This will help you so much now and later down the road.

I remember not knowing this was even possible until my second year of my first (of three) colleges!
 

lloyddean

macrumors 65816
May 10, 2009
1,001
16
Des Moines, WA
Your calculation loop can be expressed less awkwardly with.

Code:
// Loop for calculation of each room
for ( cnt = rooms; cnt--; )
 
Last edited:

FireflyMal

macrumors newbie
Original poster
Mar 19, 2012
8
0
Your calculation loop can be expressed less awkwardly with.

Code:
// Loop for calculation of each room
for ( cnt = rooms; cnt--; )
Just tried this, and when I enter 4 rooms, it asks me for 5 square footage values for rooms.

----------

Oh crap I didn't catch that you were using references.

No matter though, its better as a void function since having a double returning 0 is kind of confusing to anyone using the function since they can't use it as part of an equation or something.

Also great news that it is now working for you. One thing to definitely learn early on (if you don't know how to do it already) is to learn to use the debugger to check variable values. This will help you so much now and later down the road.

I remember not knowing this was even possible until my second year of my first (of three) colleges!
I'm going to have to check this out in Xcode. Thanks for the help and tips!
 

FireflyMal

macrumors newbie
Original poster
Mar 19, 2012
8
0
Oh crap I didn't catch that you were using references.

No matter though, its better as a void function since having a double returning 0 is kind of confusing to anyone using the function since they can't use it as part of an equation or something.

Also great news that it is now working for you. One thing to definitely learn early on (if you don't know how to do it already) is to learn to use the debugger to check variable values. This will help you so much now and later down the road.

I remember not knowing this was even possible until my second year of my first (of three) colleges!
You know, I tried this and deleted all of the reference variables, and everything returned 0. I think I need these reference variables for this to work.
 

lloyddean

macrumors 65816
May 10, 2009
1,001
16
Des Moines, WA
And how many times is "Hello!" printed?

Code:
#include <iostream>

int main()
{
    const size_t    room = 4;
    
    for ( int i = room; i--; )
    {
        std::cout << "Hello!\n";
    }

    return EXIT_SUCCESS;
}
 

chrono1081

macrumors 604
Jan 26, 2008
7,525
1,492
Isla Nublar
You know, I tried this and deleted all of the reference variables, and everything returned 0. I think I need these reference variables for this to work.
No you don't want to delete the reference variables, those stay. You just don't want a "return 0" or a "double" in front of the variable name since its a void function.

You'll want it to look like this:

Code:
void addFive(int &a, int &b)
{
     a += 5;
     b += 5;
}
Its still a void function, but the references to the variables allow them to be changed.

Take this piece of code for example:

Code:
#include <iostream>

using std::cout;
using std::string;
using std::endl;

void addFive(int &, int &);

int main (int argc, const char * argv[])
{

    
    int a = 5;
    int b = 10;
    
    cout << "Before addFive function: a = " << a << " b = " << b << endl;
    
    addFive(a, b);
    
    cout << "After addFive function: a = " << a << " b = " << b << endl;
    
    return 0;
}

void addFive(int &a, int &b)
{
    a += 5;
    b += 5;
}
This is essentially how you want your function to work.
 

FireflyMal

macrumors newbie
Original poster
Mar 19, 2012
8
0
And how many times is "Hello!" printed?

Code:
#include <iostream>

int main()
{
    const size_t    room = 4;
    
    for ( int i = room; i--; )
    {
        std::cout << "Hello!\n";
    }

    return EXIT_SUCCESS;
}
Have to run to my Calc 1 class. I'll try this when I get back home. Did you try compiling and running my code with your change to the counter by any chance? I did try your way and it asked me for square footage 5 times when I entered 4.

I believe the issue is that I ask for the initial square footage first. That first square footage question is asked outside the loop. In order for the loop to return the correct amount, I need to have (rooms - 1) to omit the square footage outside the loop.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
Yes, but not if you're writing for performance or easier to read code.
Performance? Give me a break, the example you proposed have a: initialization part, evaluation part and decrement part, thus the same.

The idea behind the idiom is that it is easier to read code if all loops that does the same job, always looks the same.
 

lloyddean

macrumors 65816
May 10, 2009
1,001
16
Des Moines, WA
Idioms are only useful if they are not awkward, hard to read or take more effort to understand.

We're going to disagree here. But that's no reason not to introduced it.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
Idioms are only useful if they are not awkward, hard to read or take more effort to understand.
Absolutely, which is why I suggested the most typical of for loops. I only commented on this since you suggested a less awkward way of doing this btw. Never mind.