Welcome to Dream.In.Code
Become a C++ Expert!

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




Job Estimate program, needs help.

 
Reply to this topicStart new topic

Job Estimate program, needs help.

eadams20
13 Oct, 2006 - 01:14 PM
Post #1

D.I.C Head
**

Joined: 30 Aug, 2006
Posts: 65


My Contributions
Here is my problem
I am trying to write a program that will estimate the number of boxes of tile needed for a job. A job is estimated by taking the dimensions of each room in feet and inches and converting these into a multiple of the tile size (rounding up any partial multiple) before multiplying to get the number of tiles for the room. A box should have 20 tiles, so I need to divide the total number needed by 20 and rounded up to get the number of boxes (they are square). Here is what I have so far:

CODE

#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>

using namespace std;

// Function prototypes
void PrintHeading(ofstream&);
void DetermineTileno(float, float, int, int, float&);
void PrintResults(ofstream&, float, float, int, int, float);

int main()
{
    // Input Variables
    float roomNumber;
    float tileSize;
    int roomWidth;
    int roomLength;
    float tileNo;

    // Declare and open output file
    ofstream dataOut;
    dataOut.open("tile.out");
    if ( !dataOut )
    { // no
        cout << "Can't open output file." << endl;
        return 1;
    }
    
    PrintHeading(dataOut);
    
    // Prompt for and read Room Number
    cout << "Input the total number of rooms to be tiled: " << endl;
    cin >> roomNumber;

    // Loop calculating room number
    while (roomNumber >= 0)
    {
        // Prompt for and read tile size, room width, room length.
        cout << "Input the size of tile in inches:" << endl;
        cin >> tileSize;
        cout << "Input the width of room (feet and inches, seperated by"
             << "a space):" << endl;
        cin >> roomWidth;
        cout << "Input the length of room (feet and inches, seperated"
            << " by a space):" << endl;
        cin >> roomLength;

        DetermineTileno(roomNumber, tileSize, roomWidth, roomLength,
                        tileNo);
        PrintResults(dataOut, roomNumber, roomWidth, roomLength,
                     tileSize, tileNo);
        // Prompt for and read loan amount
        cout << " Input and total number of rooms to be tiled;" << endl;
        cin >> roomNumber;
    }

    dataOut.close();
    return 0;
}
    //*************************************************************
    void DetermineTileno
        ( /* in */ float roomNumber,  //Room Number
          /* in */ float tileSize,    //Size of Tile
          /* in */ int roomWidth,     // Room Width
          /* in */ int roomLength,   // Room Length
          /* inout */ float& tileNo ) // Tile Number

    // Calculate the number of tile for room amount using
    // the formula lenth and width
    // Precondition
    //  Arguments have been assigned a value
    // Post condtition
    // tileNo contains the tile number as calculated by the formula

    {
        // local variables
        float roomSize;
        int tileCoverage;
    
        roomSize = roomWidth * roomLength;
        tileCoverage = tileSize * 20;
        tileNo = ((roomSize)/(tileCoverage));

    }

    //*****************************************************************

    void PrintResults( /* inout */ ofstream& dataOut,  // Output File
                       /* in */    float roomNumber,   // Room Number
                       /* in */    float tileSize,     // Tile size
                       /* in */    int roomWidth,       // Room Width
                       /* in */    int roomLength,      // Room Lenght
                       /* in */    float tileNo  )     // Tile Number

    // Prints the tile number, room number, tile size, room width,
    //  room legth, and tile number on file dataOut
    // Precondtition:
    //      File dataOut has been opened successfully &&
    //        All arguments have been assigned values
    // Postcodtion:
    //  room number, tile size, room width, room length,
    //  have all been printed on outData with proper documentation.

    {
        dataOut << fixed << setprecision(2) << setw(12) << roomNumber
                << setw(12) << tileSize << setw(12) << roomWidth
                << setw(12) << roomLength << setw(12) << endl;
    }

    //*****************************************************************

    void PrintHeading( /* inout */ ofstream& dataOut )  // Outputfile

    // Prints the heading on file dataOut for each column in the table.
    // Precondition:
    //  File dataOut has been opened successfully
    // Postcondtion:
    //  "Room Number", " Tile Size", "Room Width", "Room Length",
    //  "Tile Number", have been written of file dataOut.

    {
        dataOut << fixed << setprecision(2) << setw(12) << "Room Number"
                << setw(12) << "Tile Size" << setw(12) << "Room Width"
                << setw(12) << "Room Length" << setw(12) << "Tile Number"
                << endl;
    }



It will compile but it does not work. Can someone please help me get this program running.

Thanks in advance.
User is offlineProfile CardPM
+Quote Post

gregoryH
RE: Job Estimate Program, Needs Help.
13 Oct, 2006 - 02:29 PM
Post #2

D.I.C Regular
Group Icon

Joined: 4 Oct, 2006
Posts: 417


Dream Kudos: 50
My Contributions
QUOTE(eadams20 @ 13 Oct, 2006 - 02:14 PM) *

Here is my problem
I am trying to write a program that will estimate the number of boxes of tile needed for a job. A job is estimated by taking the dimensions of each room in feet and inches and converting these into a multiple of the tile size (rounding up any partial multiple) before multiplying to get the number of tiles for the room. A box should have 20 tiles, so I need to divide the total number needed by 20 and rounded up to get the number of boxes (they are square). Here is what I have so far:

It will compile but it does not work. Can someone please help me get this program running.

Thanks in advance.

Can you expand on what you mean by doesn't work?

The analogy is driving your car to a mechanic and saying "my car is not working"....
User is offlineProfile CardPM
+Quote Post

eadams20
RE: Job Estimate Program, Needs Help.
13 Oct, 2006 - 02:46 PM
Post #3

D.I.C Head
**

Joined: 30 Aug, 2006
Posts: 65


My Contributions
Sorry, yes, the major "doesn't work" problem is that it will not tell me how many tiles I need per room entered. I can enter the room number, the room size, the tile size, but it just loops on, it never give me the tileNO. result..


For instance it says

"Input the total number or rooms to be tiled:"
then I enter "1"
"Input the size of the tile in inches"
"12"
"Input the width of the room in inches (ft and inches seperated bya space)"
12 0
((((here is where it goes haywire))))))
"Input the legth of the room in inches (ft and inches seperated by a space):
Input the total number of rooms to be tiled;"

then it just reapeats each question the same way with the "room to tiled;" right below it.

It also gives me no answer.
User is offlineProfile CardPM
+Quote Post

gregoryH
RE: Job Estimate Program, Needs Help.
13 Oct, 2006 - 03:01 PM
Post #4

D.I.C Regular
Group Icon

Joined: 4 Oct, 2006
Posts: 417


Dream Kudos: 50
My Contributions
QUOTE(eadams20 @ 13 Oct, 2006 - 03:46 PM) *

Sorry, yes, the major "doesn't work" problem is that it will not tell me how many tiles I need per room entered. I can enter the room number, the room size, the tile size, but it just loops on, it never give me the tileNO. result..


For instance it says

"Input the total number or rooms to be tiled:"
then I enter "1"
"Input the size of the tile in inches"
"12"
"Input the width of the room in inches (ft and inches seperated bya space)"
12 0
((((here is where it goes haywire))))))
"Input the legth of the room in inches (ft and inches seperated by a space):
Input the total number of rooms to be tiled;"

then it just reapeats each question the same way with the "room to tiled;" right below it.

It also gives me no answer.


First question:
does the project restrict how you write the functions? ie are you forced to write specific functions or is that up to you?
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Job Estimate Program, Needs Help.
13 Oct, 2006 - 03:02 PM
Post #5

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
First and foremost, you are asking for feet and inches separated by a space, but taking the input using cin...the cin operator will only accept input until the first whitespace.
User is offlineProfile CardPM
+Quote Post

eadams20
RE: Job Estimate Program, Needs Help.
13 Oct, 2006 - 03:49 PM
Post #6

D.I.C Head
**

Joined: 30 Aug, 2006
Posts: 65


My Contributions
I have to use functional decompostition to solve, and code the solution using function wherever it makes sense to use them. It has to check for inches grater than 11, number of rooms less than one, and non positive deminsions .

QUOTE(gregoryH @ 13 Oct, 2006 - 04:01 PM) *

QUOTE(eadams20 @ 13 Oct, 2006 - 03:46 PM) *

Sorry, yes, the major "doesn't work" problem is that it will not tell me how many tiles I need per room entered. I can enter the room number, the room size, the tile size, but it just loops on, it never give me the tileNO. result..


For instance it says

"Input the total number or rooms to be tiled:"
then I enter "1"
"Input the size of the tile in inches"
"12"
"Input the width of the room in inches (ft and inches seperated bya space)"
12 0
((((here is where it goes haywire))))))
"Input the legth of the room in inches (ft and inches seperated by a space):
Input the total number of rooms to be tiled;"

then it just reapeats each question the same way with the "room to tiled;" right below it.

It also gives me no answer.


First question:
does the project restrict how you write the functions? ie are you forced to write specific functions or is that up to you?



I guess I will ask them to round to the nearest inch.. maybe that will make more sense

QUOTE(Amadeus @ 13 Oct, 2006 - 04:02 PM) *

First and foremost, you are asking for feet and inches separated by a space, but taking the input using cin...the cin operator will only accept input until the first whitespace.

User is offlineProfile CardPM
+Quote Post

gregoryH
RE: Job Estimate Program, Needs Help.
13 Oct, 2006 - 04:19 PM
Post #7

D.I.C Regular
Group Icon

Joined: 4 Oct, 2006
Posts: 417


Dream Kudos: 50
My Contributions
QUOTE(eadams20 @ 13 Oct, 2006 - 04:49 PM) *

I have to use functional decompostition to solve, and code the solution using function wherever it makes sense to use them. It has to check for inches grater than 11, number of rooms less than one, and non positive deminsions .


eadams,

Armadeus made a valid observation.
CODE
cout << "Input the width of room (feet and inches, seperated by"
             << "a space):" << endl;
        cin >> roomWidth;
        cout << "Input the length of room (feet and inches, seperated"
            << " by a space):" << endl;
        cin >> roomLength;


This code may behave very badly because the roomWidth included additional data which became roomLength

if you make roomWidth and roomLenght a structure like this:
CODE

struct _roomdim
{
    int feet , inches;
} roomLength, roomWidth


your code would change to:
CODE
cout << "Input the width of room (feet and inches, seperated by"
             << "a space):" << endl;
        cin >> roomWidth.feet >> roomWidth.inches;
        cout << "Input the length of room (feet and inches, seperated"
            << " by a space):" << endl;
        cin >> roomLength.feet >> roomLength.inches

Which is much easier to pass around and deal with, and fits your instructions correctly
User is offlineProfile CardPM
+Quote Post

gregoryH
RE: Job Estimate Program, Needs Help.
13 Oct, 2006 - 04:38 PM
Post #8

D.I.C Regular
Group Icon

Joined: 4 Oct, 2006
Posts: 417


Dream Kudos: 50
My Contributions
QUOTE(eadams20 @ 13 Oct, 2006 - 04:49 PM) *

I have to use functional decompostition to solve, and code the solution using function wherever it makes sense to use them.


I see you have three functions, indicating some use of functional decomp.

One of the objectives of coding is to make your code readable and maintainable. If you make more functions, you can easily take care of improved functionality.

eg

int getNumRooms ( ) ; // prevents <=0 or > limit rooms being entered

void getRoomSize( _roomdim & ) ; // confirms dimensions are sensible before returning

int getSquareTileSize ( ); // confirms size is > 0 before returning

int getTilesInBox ( ) ; // all helps to remove user typos....

If a bug crops up, you will know exactly which function to go and fix...

This post has been edited by gregoryH: 13 Oct, 2006 - 04:39 PM
User is offlineProfile CardPM
+Quote Post

eadams20
RE: Job Estimate Program, Needs Help.
14 Oct, 2006 - 08:15 PM
Post #9

D.I.C Head
**

Joined: 30 Aug, 2006
Posts: 65


My Contributions
CODE

#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>

using namespace std;

// Function prototypes
void PrintHeading();
void DetermineTileno(float, float, int, int, float&);
void PrintResults( float, float, int, int, float);

int main()
{
    // Input Variables
    float roomNumber;
    float tileSize;
    int roomLength;
    int roomWidth;
    float tileNo;

    
    PrintHeading();
    
    // Prompt for and read Room Number
    cout << "Input the total number of rooms to be tiled: " << endl;
    cin >> roomNumber;
    // the tile size is the same for all rooms
    // Prompt for and read tile size, room width, room length.
        cout << "Input the size of tile in inches:" << endl;
        cin >> tileSize;

    // Loop calculating room number
    while (roomNumber >= 1)
    {
        }
         struct _roomdim;
        {
           int feet, inches;
           roomLength, roomWidth;
          
    }
        cout << "Input the width of room (feet and inches, seperated by "
             << "a space):" << endl;
        cin >> roomWidth.feet >> roomWidth.inches;
        cout << "Input the length of room (feet and inches, seperated"
            << " by a space):" << endl;
        cin >> roomLength.feet >> roomLength.inches;


        DetermineTileno(roomNumber, tileSize, roomLength, roomWidth,
                        tileNo);
        PrintResults( roomNumber, tileSize, roomLength, roomWidth,  
                     tileNo);
        
    
    


    

    {
        // local variables
        float roomSize;
        int tileCoverage;
    
        roomSize = roomLength * roomWidth;
        tileCoverage = tileSize * 20;
        tileNo = ((roomSize)/(tileCoverage));

    }
//    dataOut.close();
    cin.get();
    cin.get();
    return 0;
}



here are the errors I get now
QUOTE

------ Build started: Project: Ch7ex2cpp, Configuration: Debug Win32 ------

Compiling...
ch7ex2cpp.cpp
c:\Documents and Settings\Emily Adams\My Documents\Visual Studio Projects\Ch7ex2cpp\ch7ex2cpp.cpp(45) : error C2228: left of '.feet' must have class/struct/union type
type is 'int'
c:\Documents and Settings\Emily Adams\My Documents\Visual Studio Projects\Ch7ex2cpp\ch7ex2cpp.cpp(45) : error C2228: left of '.inches' must have class/struct/union type
type is 'int'
c:\Documents and Settings\Emily Adams\My Documents\Visual Studio Projects\Ch7ex2cpp\ch7ex2cpp.cpp(48) : error C2228: left of '.feet' must have class/struct/union type
type is 'int'
c:\Documents and Settings\Emily Adams\My Documents\Visual Studio Projects\Ch7ex2cpp\ch7ex2cpp.cpp(48) : error C2228: left of '.inches' must have class/struct/union type
type is 'int'
c:\Documents and Settings\Emily Adams\My Documents\Visual Studio Projects\Ch7ex2cpp\ch7ex2cpp.cpp(67) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
c:\Documents and Settings\Emily Adams\My Documents\Visual Studio Projects\Ch7ex2cpp\ch7ex2cpp.cpp(68) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data

Build log was saved at "file://c:\Documents and Settings\Emily Adams\My Documents\Visual Studio Projects\Ch7ex2cpp\Debug\BuildLog.htm"
Ch7ex2cpp - 4 error(s), 2 warning(s)


---------------------- Done ----------------------

Build: 0 succeeded, 1 failed, 0 skipped

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 07:31PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month