PLEASE help me!

I am having trouble how to create a function called output which will receive all 3 arrays created in Discount Auto Parts program and then print the values. When the output has finished, this execute should return to main and create an array with 2 rows, 5 columns and then, copy the values from array 1 into the first row of your 2-D array. This is my Discount Auto Parts program and I am still getting so many error at end. PLEASE HELP ME OUT.

#include

using std::cout;
using std::cin;

#include
using std::setprecision;



int main()
{
double rate = 44.00;
double hours[5]; //This variable holds the number of hours worked
double value[5]; //This variable holds the cost of parts
double totalCost[5]; //This variable holds the total cost for a single customer

int i; //Counter for loop

for (i=0; i<5; ++i){


cout << "Please Hours Worked
";
cin >> hours[i];
cout << "Please Parts Value
";
cin >> value[i];

totalCost[i] = (rate * hours[i]) + value[i];
}
for (i=0;i<5;++i){

cout << "Price of labor is:" << setprecision(2)<< (rate * hours[i]) << "
";
cout << "Cost of parts is:" << value[i] << "
";
cout << "Total price is:" <<totalCost[i] << "
";
}

return 0;
}

Comments

  • [b][red]This message was edited by stober at 2004-5-31 13:46:34[/red][/b][hr]
    [blue]Here's what the function prototype should look like.[/blue]

    [code]
    void output(double hours[],double value[], double totalCost[]);

    ...
    // call it like this somewhere in main()
    output(hours,value,totalCost);
    [/code]

    : I am having trouble how to create a function called output which will receive all 3 arrays created in Discount Auto Parts program and then print the values. When the output has finished, this execute should return to main and create an array with 2 rows, 5 columns and then, copy the values from array 1 into the first row of your 2-D array. This is my Discount Auto Parts program and I am still getting so many error at end. PLEASE HELP ME OUT.
    :
    : #include
    :
    : using std::cout;
    : using std::cin;
    :
    : #include
    : using std::setprecision;
    :
    :
    :
    : int main()
    : {
    : double rate = 44.00;
    : double hours[5]; //This variable holds the number of hours worked
    : double value[5]; //This variable holds the cost of parts
    : double totalCost[5]; //This variable holds the total cost for a single customer
    :
    : int i; //Counter for loop
    :
    : for (i=0; i<5; ++i){
    :
    :
    : cout << "Please Hours Worked
    ";
    : cin >> hours[i];
    : cout << "Please Parts Value
    ";
    : cin >> value[i];
    :
    : totalCost[i] = (rate * hours[i]) + value[i];
    : }
    : for (i=0;i<5;++i){
    :
    : cout << "Price of labor is:" << setprecision(2)<< (rate * hours[i]) << "
    ";
    : cout << "Cost of parts is:" << value[i] << "
    ";
    : cout << "Total price is:" <<totalCost[i] << "
    ";
    : }
    :
    : return 0;
    : }
    :
    :



  • : [b][red]This message was edited by stober at 2004-5-31 13:46:34[/red][/b][hr]
    : [blue]Here's what the function prototype should look like.[/blue]
    :
    : [code]
    : void output(double hours[],double value[], double totalCost[]);
    :
    : ...
    : // call it like this somewhere in main()
    : output(hours,value,totalCost);
    : [/code]
    :
    : : I am having trouble how to create a function called output which will receive all 3 arrays created in Discount Auto Parts program and then print the values. When the output has finished, this execute should return to main and create an array with 2 rows, 5 columns and then, copy the values from array 1 into the first row of your 2-D array. This is my Discount Auto Parts program and I am still getting so many error at end. PLEASE HELP ME OUT.
    : :
    : : #include
    : :
    : : using std::cout;
    : : using std::cin;
    : :
    : : #include
    : : using std::setprecision;
    : :
    : :
    : :
    : : int main()
    : : {
    : : double rate = 44.00;
    : : double hours[5]; //This variable holds the number of hours worked
    : : double value[5]; //This variable holds the cost of parts
    : : double totalCost[5]; //This variable holds the total cost for a single customer
    : :
    : : int i; //Counter for loop
    : :
    : : for (i=0; i<5; ++i){
    : :
    : :
    : : cout << "Please Hours Worked
    ";
    : : cin >> hours[i];
    : : cout << "Please Parts Value
    ";
    : : cin >> value[i];
    : :
    : : totalCost[i] = (rate * hours[i]) + value[i];
    : : }
    : : for (i=0;i<5;++i){
    : :
    : : cout << "Price of labor is:" << setprecision(2)<< (rate * hours[i]) << "
    ";
    : : cout << "Cost of parts is:" << value[i] << "
    ";
    : : cout << "Total price is:" <<totalCost[i] << "
    ";
    : : }
    : :
    : : return 0;
    : : }
    : :
    : :
    :
    :
    :
    :
    I still couldn't get this problem right. Could you show me the whole part of it. That way I can get it clear.

  • : : [blue]Here's what the function prototype should look like.[/blue]
    : :
    : : [code]
    : : void output(double hours[],double value[], double totalCost[]);
    : :
    : : ...
    : : // call it like this somewhere in main()
    : : output(hours,value,totalCost);
    : : [/code]
    : :
    : : : I am having trouble how to create a function called output which will receive all 3 arrays created in Discount Auto Parts program and then print the values. When the output has finished, this execute should return to main and create an array with 2 rows, 5 columns and then, copy the values from array 1 into the first row of your 2-D array. This is my Discount Auto Parts program and I am still getting so many error at end. PLEASE HELP ME OUT.
    : : :
    : : : #include
    : : :
    : : : using std::cout;
    : : : using std::cin;
    : : :
    : : : #include
    : : : using std::setprecision;
    : : :
    : : :
    : : :
    : : : int main()
    : : : {
    : : : double rate = 44.00;
    : : : double hours[5]; //This variable holds the number of hours worked
    : : : double value[5]; //This variable holds the cost of parts
    : : : double totalCost[5]; //This variable holds the total cost for a single customer
    : : :
    : : : int i; //Counter for loop
    : : :
    : : : for (i=0; i<5; ++i){
    : : :
    : : :
    : : : cout << "Please Hours Worked
    ";
    : : : cin >> hours[i];
    : : : cout << "Please Parts Value
    ";
    : : : cin >> value[i];
    : : :
    : : : totalCost[i] = (rate * hours[i]) + value[i];
    : : : }
    : : : for (i=0;i<5;++i){
    : : :
    : : : cout << "Price of labor is:" << setprecision(2)<< (rate * hours[i]) << "
    ";
    : : : cout << "Cost of parts is:" << value[i] << "
    ";
    : : : cout << "Total price is:" <<totalCost[i] << "
    ";
    : : : }
    : : :
    : : : return 0;
    : : : }
    : : :
    : : :
    : :
    : :
    : :
    : :
    : I still couldn't get this problem right. Could you show me the whole part of it. That way I can get it clear.
    :

    [blue]Since this is homework, post the code that you can't get right and we'll try to help[/blue]
  • :
    : : : [blue]Here's what the function prototype should look like.[/blue]
    : : :
    : : : [code]
    : : : void output(double hours[],double value[], double totalCost[]);
    : : :
    : : : ...
    : : : // call it like this somewhere in main()
    : : : output(hours,value,totalCost);
    : : : [/code]
    : : :
    : : : : I am having trouble how to create a function called output which will receive all 3 arrays created in Discount Auto Parts program and then print the values. When the output has finished, this execute should return to main and create an array with 2 rows, 5 columns and then, copy the values from array 1 into the first row of your 2-D array. This is my Discount Auto Parts program and I am still getting so many error at end. PLEASE HELP ME OUT.
    : : : :
    : : : : #include
    : : : :
    : : : : using std::cout;
    : : : : using std::cin;
    : : : :
    : : : : #include
    : : : : using std::setprecision;
    : : : :
    : : : :
    : : : :
    : : : : int main()
    : : : : {
    : : : : double rate = 44.00;
    : : : : double hours[5]; //This variable holds the number of hours worked
    : : : : double value[5]; //This variable holds the cost of parts
    : : : : double totalCost[5]; //This variable holds the total cost for a single customer
    : : : :
    : : : : int i; //Counter for loop
    : : : :
    : : : : for (i=0; i<5; ++i){
    : : : :
    : : : :
    : : : : cout << "Please Hours Worked
    ";
    : : : : cin >> hours[i];
    : : : : cout << "Please Parts Value
    ";
    : : : : cin >> value[i];
    : : : :
    : : : : totalCost[i] = (rate * hours[i]) + value[i];
    : : : : }
    : : : : for (i=0;i<5;++i){
    : : : :
    : : : : cout << "Price of labor is:" << setprecision(2)<< (rate * hours[i]) << "
    ";
    : : : : cout << "Cost of parts is:" << value[i] << "
    ";
    : : : : cout << "Total price is:" <<totalCost[i] << "
    ";
    : : : : }
    : : : :
    : : : : return 0;
    : : : : }
    : : : :
    : : : :
    : : :
    : : :
    : : :
    : : :
    : : I still couldn't get this problem right. Could you show me the whole part of it. That way I can get it clear.
    : :
    :
    : [blue]Since this is homework, post the code that you can't get right and we'll try to help[/blue]
    :

    This is the best I could do.

    // Initializing an array.
    #include <iostream>

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

    #include

    using std::setw;

    int main()
    {
    int n[ 2 ][ 5 ]; // n is an array of 2 integers

    // initialize elements of array n to 0
    for ( int i = 0; i < 2; i++ )
    for (int k = 0; k < 5 ; k++)
    n[ i ][ k ] = 0; // set element at location i to 0

    cout << "Element" << setw( 7 ) << "Value" << endl;

    // output contents of array n in tabular format
    for ( int j = 0; j < 2; j++ )

    for (int l =0 ; l < 5 ; l++)

    cout << setw( 7 ) << j << setw( 13 ) << n[ j ][ l ] << endl;

    return 0; // indicates successful termination

    } // end main

  • where is the function called output()? I already gave you the function prototype, so all you have to do is write it as instructed.
  • //////////////////////////////////////////////////////////////
    #include
    using namespace std;

    void output(double hours[],double value[], double totalCost[],
    double& rate);

    const int NUM_CUSTOMERS = 5;

    int main()
    {
    double rate = 44.00;
    double hours[NUM_CUSTOMERS];
    double value[NUM_CUSTOMERS];
    double totalCost[NUM_CUSTOMERS];

    for(int i=0; i < NUM_CUSTOMERS; i++)
    {
    cout << "Please input the number of hours worked: ";
    cin >> hours[i];
    cout << "Please input the value of the parts: ";
    cin >> value[i];
    cout << "
    ";
    totalCost[i] = (rate * hours[i]) + value[i];
    }

    output(hours, value, totalCost, rate);

    system("PAUSE");
    return 0;
    }

    void output(double hours[],double value[], double totalCost[],
    double& rate)
    {
    for (int j=0; j < NUM_CUSTOMERS; j++)
    {
    cout << "Price of labor is: " << (rate * hours[j]) << ".
    ";
    cout << "Cost of parts is: " << value[j] << ".
    ";
    cout << "Total price is: " <<totalCost[j] << ".

    ";
    }
    }
    //////////////////////////////////////////////////////////////

    This is the way I would have done it, quite simple actually.
    I'm not familiar with the setprecision() function, and tbh I
    didn't see the need for it (though that may be because I don't
    know what it does :P).
  • : //////////////////////////////////////////////////////////////
    : #include
    : using namespace std;
    :
    : void output(double hours[],double value[], double totalCost[],
    : double& rate);
    :
    : const int NUM_CUSTOMERS = 5;
    :
    : int main()
    : {
    : double rate = 44.00;
    : double hours[NUM_CUSTOMERS];
    : double value[NUM_CUSTOMERS];
    : double totalCost[NUM_CUSTOMERS];
    :
    : for(int i=0; i < NUM_CUSTOMERS; i++)
    : {
    : cout << "Please input the number of hours worked: ";
    : cin >> hours[i];
    : cout << "Please input the value of the parts: ";
    : cin >> value[i];
    : cout << "
    ";
    : totalCost[i] = (rate * hours[i]) + value[i];
    : }
    :
    : output(hours, value, totalCost, rate);
    :
    : system("PAUSE");
    : return 0;
    : }
    :
    : void output(double hours[],double value[], double totalCost[],
    : double& rate)
    : {
    : for (int j=0; j < NUM_CUSTOMERS; j++)
    : {
    : cout << "Price of labor is: " << (rate * hours[j]) << ".
    ";
    : cout << "Cost of parts is: " << value[j] << ".
    ";
    : cout << "Total price is: " <<totalCost[j] << ".

    ";
    : }
    : }
    : //////////////////////////////////////////////////////////////
    :
    : This is the way I would have done it, quite simple actually.
    : I'm not familiar with the setprecision() function, and tbh I
    : didn't see the need for it (though that may be because I don't
    : know what it does :P).
    :
    At end of it,does it suppose to show: } // end total function because I don't see it. Am I right?
  • [b][red]This message was edited by Balistix at 2004-6-1 11:5:59[/red][/b][hr]
    : At end of it,does it suppose to show: } // end total function because I don't see it. Am I right?
    :

    ? I don't get what you're saying. English plz :D
    That code I posted shouldn't be missing anything or have anything extra added. It compiled fine on mine (I'm using Dev-C++) and I got a friend to compile it on his machine with VC++ 6.0 so as far as I can tell everything's fine.

    Also, if you don't understand some of that code (such as the basic idea of function -- such as that output function) or what exactly is happening (as stober pointed out it seems like this is "homework" :P) I would STRONGLY SUGGEST that you don't just copy/paste the code and pass it in. Take the time to study it and practice coding with it. It might help now but it will definitely bite you in the *ss somewhere in the near future with other programs.

    Reply back and let me know if that at least compiled for you.



  • : [b][red]This message was edited by Balistix at 2004-6-1 11:5:59[/red][/b][hr]
    : : At end of it,does it suppose to show: } // end total function because I don't see it. Am I right?
    : :
    :
    : ? I don't get what you're saying. English plz :D
    : That code I posted shouldn't be missing anything or have anything extra added. It compiled fine on mine (I'm using Dev-C++) and I got a friend to compile it on his machine with VC++ 6.0 so as far as I can tell everything's fine.
    :
    : Also, if you don't understand some of that code (such as the basic idea of function -- such as that output function) or what exactly is happening (as stober pointed out it seems like this is "homework" :P) I would STRONGLY SUGGEST that you don't just copy/paste the code and pass it in. Take the time to study it and practice coding with it. It might help now but it will definitely bite you in the *ss somewhere in the near future with other programs.
    :
    : Reply back and let me know if that at least compiled for you.
    :
    :
    :
    :
    Yes it is. There is another problem that I actually did on my own and it's not 100% right. I was trying to create a program with 4 different variables, an integer, a double, a character and a boolean. Than, add the program 4 pointers, an integer, a double, a character and a boolean. I am just having a hard time finding the right codes.





  • : [b][red]This message was edited by Balistix at 2004-6-1 11:5:59[/red][/b][hr]
    : : At end of it,does it suppose to show: } // end total function because I don't see it. Am I right?
    : :
    :
    : ? I don't get what you're saying. English plz :D
    : That code I posted shouldn't be missing anything or have anything extra added. It compiled fine on mine (I'm using Dev-C++) and I got a friend to compile it on his machine with VC++ 6.0 so as far as I can tell everything's fine.
    :
    : Also, if you don't understand some of that code (such as the basic idea of function -- such as that output function) or what exactly is happening (as stober pointed out it seems like this is "homework" :P) I would STRONGLY SUGGEST that you don't just copy/paste the code and pass it in. Take the time to study it and practice coding with it. It might help now but it will definitely bite you in the *ss somewhere in the near future with other programs.
    :
    : Reply back and let me know if that at least compiled for you.
    :
    :
    :
    :
    I don't see 2-D array.

  • : Yes it is. There is another problem that I actually did on my own and it's not 100% right. I was trying to create a program with 4 different variables, an integer, a double, a character and a boolean. Than, add the program 4 pointers, an integer, a double, a character and a boolean. I am just having a hard time finding the right codes.
    :
    :
    :
    www.cplusplus.com/doc/tutorial

    If you're having problems finding the right code I'd suggest buying a book with lessons/references...there is NO online tutorial to my knowledge than can teach c++ like a good book can. That being said, if you can't afford some of these books (I would know, I'm a student as I'm sure a lot of us are on this board :D )I'd recommend the tutorial above at cplusplus.com. That should help get you in the right direction with basic codes. gl :D
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories