program that uses multiple funtions

This is a discussion on program that uses multiple funtions within the C++ Programming forums, part of the General Programming Boards category; Hi could someone please take a look at this program and let me know what is needed to make it ...

  1. #1
    Registered User mike's Avatar
    Join Date
    Aug 2001
    Posts
    12

    program that uses multiple funtions

    Hi could someone please take a look at this program and let me know what is needed to make it right. first of all i cant get the formating of the numbers right. i have tried set precision and fixed but some thing is wrong. as far as my funtions go there are some blank ones that im working on but i am wondering before i get to far if what i have is correct. thanks for any help that you can offer. i have attached the source code
    Attached Files Attached Files

  2. #2
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368
    The code is gonna have to be in a more readable format that that, sorry.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    14
    I get to many warnings in link: argc, argv and discount are never used in function main(int,char**)

    James

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    381
    >>The code is gonna have to be in a more readable format that that, sorry.

    I agree. Relly the first thing they should teach new programmers is how to lay out thier code.

  5. #5
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    What would probably help him are suggestions how to achieve better readability...


    Watch those linebreaks. Set them at logical borders. Only one at a time. Example of better formatting:

    Code:
    int main( int argc, char* argv[] )
    {
    	int length = 0;
    	int width = 0;
    	int area = 0;
    	double discount = 0;
    
    	cout << "Length of room (feet)? ";
    	cin >> length;
    
    	cout << "Width of room (feet)? ";
    	cin >> width;
    
    	cout << "Customer discount (precent)? ";
    	cin >> precentDis;
    
    	cout << "Cost per square foot (xxx.xx)? ";
    	cin >> priceCarpet;
    Each logical Unit ( Ask for input X, get input X ) now resides in one optical block.

    Also, use more spaces. Don't put all your code into one line without breaks. Breaks at logical borders make reading easier.

    Indentation:
    each { forces an additional level of indentation, each } takes one back. In your main, the variable declarations are on the same line as the {. Put a tab there for each line. Other functions miss tabs at all.

    As you know how to use arguments and return data in functions, get rid of the global variables.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  6. #6
    Registered User mike's Avatar
    Join Date
    Aug 2001
    Posts
    12

    Up date layout of code (I hope this will help you help me)

    #include <iostream.h> // add library
    #include <iomanip.h>

    const double LABOR_COST = 0.35;
    // define constant
    const double TAX_RATE = 8.5;



    double priceCarpet; //global variables
    int precentDis=0;
    double discount=0;

    void getData (void); // funtion prototypes
    void calculate (void);
    double calcInstall (double price, double labor);
    double calcSubTotal (double sub);
    double calcTotal (double total);
    void printResult (void);
    void printMeasurement (void);
    void printCharges (void);





    int main(int argc, char* argv[])
    {
    int length=0; // declare variables
    int width=0;
    int area=0;
    double discount=0;




    cout<<"Length of room (feet)? ";
    cin>>length;

    cout<<"Width of room (feet)? ";
    cin>>width;

    cout<<"Customer discount (precent)? ";
    cin>>precentDis;

    cout<<"Cost per square foot (xxx.xx)? ";
    cin>>priceCarpet;

    cout<<""<<endl;
    cout<<setw(23)<<"MEASURMENT"<<endl;
    cout<<""<<endl;

    cout<<"Length "<<setw(16)<<length<<" feet"<<endl;

    cout<<"Width"<<setw(18)<<width<<" feet"<<endl;

    area=width*length;
    cout<<"Area"<<setw(19)<<area<<" square feet\n"<<endl;


    cout<<setw(20)<<"CHARGES"<<endl;
    cout<<""<<endl;
    cout<<"DESCRIPTION\tCOST/SQ.FT.\tCHARGE/ROOM"<<endl;
    cout<<"-----------\t";
    cout<<"-----------\t";
    cout<<"-----------"<<endl;


    cout<<"Carpet"<<setw(20)<<priceCarpet<<setw(17)<<p riceCarpet*area<<endl;

    cout<<"Labor"<<setw(21)<<LABOR_COST<<setw(15)<<LAB OR_COST*area<<endl;
    cout<<"\t\t\t\t-----------";
    cout<<""<<endl;



    calculate(); //call funtion calculate



    return 0;
    }


    void getData (void)
    {


    }

    void calculate (void)

    {

    double price=0; // calcInstall variable
    double labor=0; // calcInstall variable
    double total=0; // calTotal variable
    double sub=0; // calcSubTotal variable
    double tax=0;


    priceCarpet= calcInstall(price, labor);// call funtion calcInstall

    discount=priceCarpet*precentDis;
    cout<<"Discount"<<setw(17)<<precentDis<<'%'<<setio sflags(ios::showpoint)
    <<setw(14)<<discount<<endl;
    cout<<"\t\t\t\t-----------";
    cout<<""<<endl;


    sub=calcSubTotal(sub);// call funtion calcSubTotal

    tax=sub*TAX_RATE;
    cout<<"Tax"<<setiosflags(ios::showpoint)<<setw(42) <<tax<<endl;

    total=calcTotal(total);// call funtion calcTotal
    }

    double calcInstall (double price , double labor)
    {

    price=priceCarpet*100;
    labor=LABOR_COST*100;
    cout<<"INSTALLED PRICE"<<setiosflags(ios::showpoint)
    <<setw(18)<<'$'<<priceCarpet<<endl;

    return (price+labor);
    }




    double calcSubTotal(double sub)

    {

    sub=priceCarpet*100-discount;
    cout<<"SUBTOTAL"<<setiosflags(ios::showpoint)
    <<setw(25)<<'$'<<sub<<endl;

    return(sub);
    }





    double calcTotal(double total)

    {


    total=priceCarpet-precentDis*TAX_RATE;
    cout<<"TOTAL"<<setiosflags(ios::showpoint)
    <<setw(28)<<setprecision(6)<<'$'<<total<<endl;


    return(total);
    }



    void printResult (void)
    {


    }



    void printMeasurement (void)
    {




    }




    void printCharges (void)
    {





    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  2. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 04:39 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Replies: 18
    Last Post: 12-05-2003, 12:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21