4 Replies - 235 Views - Last Post: 25 November 2012 - 11:18 PM Rate Topic: -----

#1 phanton612  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 13-November 12

void function Problem

Posted 25 November 2012 - 10:42 PM

Write a program that displays the status of an order. The program should have a function that asks for the following data:

1. The number of spools ordered
2. The number of spools in stock
3. If there are special shipping and handling charges
(Shipping and handling is normally $10 per spool) If there are special charges, it should ask for special charges per spool.

The gathered data should be passed as arguments to another function that displays:

1. The number of spools ready to ship from current stock.
2. The number of spools on backorder (if the number ordered is greater than what is in stock)
3. Subtotal of the portion ready to ship (the number of spools ready to ship times $100)
4. Total shipping and handling charges on the portion ready to ship
5. Total of the order ready to ship

The shipping and handling parameter in the second function should have the default arguments 10.00.

Input validation:

1. Do not accept numbers less than 1 for spools ordered
2. Do not accept number less than 0 for spools in stock or shipping and handling charges.

Quote

It tells me that spoolsordered is undeclared?



#include <iostream>
using namespace std;


void orderInfo(int& spoolsordered, int& spoolsinstock, double& specialcharges);
void display(int spoolsordered, int spoolsinstock, double specialcharges);



int main()
{ 
orderedInfo(spoolsordered, spoolsinstock, specialcharges);
cout << " the spoolsordered is " << spoolsordered << " ";

    system("pause");
	return 0;
}

////////////////////////////////////////////////////////////////////////////////
void orderInfo(int& spoolsordered, int& spoolsinstock, double& specialcharges)
{
    cout << " Please enter the number spools ordered: ";
    cin >> spoolsordered;
    
    cout << " Please enter the spools in stock: ";
    cin >> spoolsinstock;
    
    cout << " Please enter any specail charges: ";
    cin >> specialcharges;
}
////////////////////////////////////////////////////////////////////////////////


Is This A Good Question/Topic? 0
  • +

Replies To: void function Problem

#2 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1072
  • View blog
  • Posts: 4,532
  • Joined: 09-June 09

Re: void function Problem

Posted 25 November 2012 - 10:45 PM

Function parameters are not simply placeholders, they are meant to be passed into a function.

Take a read: http://www.cplusplus...rial/functions/
Was This Post Helpful? 0
  • +
  • -

#3 phanton612  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 13-November 12

Re: void function Problem

Posted 25 November 2012 - 11:01 PM

View Postjjl, on 25 November 2012 - 10:45 PM, said:

Function parameters are not simply placeholders, they are meant to be passed into a function.

Take a read: http://www.cplusplus...rial/functions/


so would i just clear out all the stuff inside the parameters?

like

#include <iostream>
using namespace std;


void orderInfo();
void display(int spoolsordered, int spoolsinstock, double specialcharges);



int main()
{ 
orderedInfo();
cout << " the spoolsordered is " << spoolsordered << " ";

    system("pause");
	return 0;
}

////////////////////////////////////////////////////////////////////////////////
void orderInfo()
{
    cout << " Please enter the number spools ordered: ";
    cin >> spoolsordered;
    
    cout << " Please enter the spools in stock: ";
    cin >> spoolsinstock;
    
    cout << " Please enter any specail charges: ";
    cin >> specialcharges;
}
////////////////////////////////////////////////////////////////////////////////


when i do that it just says orderInfo is undeclared
Was This Post Helpful? 0
  • +
  • -

#4 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: void function Problem

Posted 25 November 2012 - 11:13 PM

You also need to look into the names of functions...orderedInfo and orderInfo are considered as two different functions...

Also, for your spoolsordered, spoolsinstock and specialcharges, they need to be declared first before they can be initialized.

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#5 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1072
  • View blog
  • Posts: 4,532
  • Joined: 09-June 09

Re: void function Problem

Posted 25 November 2012 - 11:18 PM

Quote

so would i just clear out all the stuff inside the parameters?

No, you need to define the variables within main and then pass them as parameters. Your function accepts references to variables, therefore they need memory to reference from.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1