Heres the homework problem:
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.
===============================
I get an error "Void getInfo(void)" : overloaded function differs only by return type from "double getInfo(void)"
I have several return commands but I do not know how to write the code in sections for the first function. I think that maybe the issue. Here is what I got if anyone can lend a hand and Remember I am a BEGINNER so please explain any changes you make so I understand what is the purpose, etc.
Note: I have not learned arrays yet so please omit. Thanks!

#include <iostream>
#include <iomanip>
using namespace std;

void getInfo(double &, double &, double = 10.0);
void display(double backOrder, double spoolsOrdered, double subTotal, double shipping,
			 double total);

int main()
{
	double getInfo(),
	       display();

	void getInfo()
	{
		char s&h;
		double spools,
			   stock,
			   charges;

		cout << "Enter the amount of spools ordered: ";
		cin >> spools;

		while(spools < 1)
		{
			cout << "Enter a number greater than 0: ";
			cin >> spools;
		}
		return spools;

		cout << "Enter the amount of spools in stock: ";
		cin >> stock;

		while(stock < 0)
		{
			cout << "Enter a number greater than 0: ";
			cin >> stock;
		}
		return stock;

		cout << "Are there any special S&H Charges?: ";
		cin >> s&h;

		if(s&h == 'Y' || s&h == 'y')
		{
			cout << "Please enter in the amount of the special charges: ";
			cin >> charges;
		
			while(charges < 0)
			{
				cout << "Enter number greater than 0: ";
				cin >> charges;
			}
			return charges;
		}

	void display(double spools, double stock, double charges)
	{
		double backOrder,
			   spoolsOrdered,
			   subTotal,
			   shipping,
			   total;

			backOrder = spools - stock;
			cout << "The amount of spools on back order is: " << backOrder << ".\n";

			spoolsOrdered = spools - backOrder;
			cout << "Spools ready to ship now: " << spoolsOrdered << ".\n";

			subTotal = spoolsOrdered * 100;
			cout << "Your subtotal before Shipping & Handling fees are $"
				 << subTotal << endl;

			shipping = subTotal + charges;
			cout << "Your cost of shipping the spools of copper is $" 
				 << shipping << endl;

			total = shipping + subTotal;
			cout << "Your total cost of order is: $" << total << ".\n";
		}
	}

Recommended Answers

All 2 Replies

Function definitions must appear out of the main(). I like to put the function prototypes first. Then open main, call functions, and close main. Then write the function definitions after main. Line 11 is also a problem. You don't include a data type for a function call. Also remember that void functions have no return value. Your current code is very confusing to me due to the functions being declared in main. Also remember to keep your parameters consistent. The function prototype, call, and definition must all have the same number of parameters, and they must be of corresponding data types. Also, you don't set values for the variables you include as parameters in the function prototype. (line 5) Try to resolve these problems before you tackle the rest of the program.

I fixed up the code so it runs and threw in a few comments.

As GrnXtrm said you have a bunch of errors that mainly has to do with learning the format of a program. I hope my fix up/comments help.

#include <iostream>
#include <iomanip>
using namespace std;

//prototypes
//I changed your getInfo prototype because it was different from the one below
void getInfo(double &spools, double &stock, double &charges); //pass by reference so we do not need to make global variables
void display(double spools, double stock, double charges);

int main()
{
	double spools, stock, charges; //declare local vaiables
	
	getInfo(spools, stock, charges); //sets the variables based on user input
	display(spools, stock, charges); //displays information
	
	system("PAUSE");
	return 0;
}

//declare function outside of other functions(main)

void getInfo(double &spools, double &stock, double &charges)
{
	charges = 0; //sets special charges to 0 (not sure how you really want this done)
	char snh; //
	double chargesSet; //variable for special charges to be added to charges

	cout << "Enter the amount of spools ordered: ";
	cin >> spools;

	while(spools < 1)
	{
		cout << "Enter a number greater than 0: ";
		cin >> spools;
	}
	//you had return here which would stop the function from going any further

	cout << "Enter the amount of spools in stock: ";
	cin >> stock;

	while(stock < 0)
	{
		cout << "Enter a number greater than 0: ";
		cin >> stock;
	}
	//you had return here which would stop the function from going any further
	
	cout << "Are there any special S&H Charges?(y or n): ";
	cin >> snh;

	if(snh == 'Y' || snh == 'y')
	{
		cout << "Please enter in the amount of the special charges: ";
		cin >> chargesSet;
	
		while(chargesSet < 0)
		{
			cout << "Enter number greater than 0: ";
			cin >> chargesSet;
		}
		charges = chargesSet; //sets the charges to the special charge input
	}
	
	//since variables were passed by reference you do not need to return anything
	//to modify the local variables
}

void display(double spools, double stock, double charges)
{
	double backOrder, spoolsOrdered, subTotal, shipping, total;
	
	backOrder = spools - stock;
	if( backOrder < 0 ) //checks to see if backOrder variable is negative and sets to zero
		backOrder = 0;
	cout << endl;
	cout << "The amount of spools on back order is: " << backOrder << ".\n";
	
	spoolsOrdered = spools - backOrder;
	cout << "Spools ready to ship now: " << spoolsOrdered << ".\n";
	
	subTotal = spoolsOrdered * 100;
	cout << "Your subtotal before Shipping & Handling fees are $" << subTotal << endl;
	
	shipping = spoolsOrdered*10 + charges; //your fourmula was wrong you might want to change
										   //depending on how you want to set your charges
	cout << "Your cost of shipping the spools of copper is $" << shipping << endl;
	
	total = shipping + subTotal;
	cout << "Your total cost of order is: $" << total << ".\n";
}

As I mentioned in the comments you might want to change how the charges work because I am not sure how you want that to be.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.