### need help with my homework.

I keep getting an error for the following program. I'm not sure what is wrong with it, and keep changing things to no avail. Any help would be appreciated!

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899`` ``````/* Dustin Nieffenegger, COMS 229 Page 374 Problem 19 Stock Profit The Profit from the sale of a stock can be calculated as follows: Profit = ((NS * SP)-SC)-((NS * PP) + PC) where NS is the number of shares, SP is the sale price per share, SC is the sale commis- sion paid, PP is the purchase price per share, and PC is the purchase commission paid. If the calculation yields a positive value, then the sale of the stock resulted in a profit. If the calculation yields a negative number, then the sale resulted in a loss. Write a function that accepts as arguments the number of shares, the purchase price per share, the purchase commission paid, the sale price per share, and the sale com- mission paid. The function should return the profit (or loss) from the sale of stock. Demonstrate the function in a program that asks the user to enter the necessary data and displays the amount of the profit or loss. */ #include using namespace std; int NS; // Number of shares double SP; // Selling Price double SC; // Sales commission paid double PP; // Purchase Price double PC; // Purchase commission paid // Function prototypes double profit(); void warning(); int main() { cout << "You are selling stock.\n"; // Input Number of shares cout << "How many shares are you selling?\n"; cin >> NS; while (NS < 1){ cout << "You must sell at least one share.\n"; cout << "How many shares are you selling?\n"; cin >> NS; } // Input Sales Price cout << "How much are you selling the stock for?\n"; cin >> SP; while (SP <= 0.0){ warning(); cout << "How much are you selling the stock for?\n"; cin >> SP; } // Input Sales commission cout << "How much must you pay the broker?\n"; cin >> SC; while (SC <= 0.0){ warning(); cout << "How much must you pay the broker?\n"; cin >> SC; } // Input Purchase price cout << "How much did you initially buy the share for?\n"; cin >> PP; while (PP <= 0.0){ warning(); cout << "How much did you initially buy the share for?\n"; cin >> PP; } // Input Purchase commission cout << "How much did you initially pay the broker?\n"; cin >> PC; while (PC <= 0.0){ warning(); cout << "How much did you initially pay the broker?\n"; cin >> PC; } cout << "Total profit is " << profit(NS,SP,SC,PP,PC); return 0; } double profit(int NS, double SP, double SC, double PP, double PC) { double result; result = (((double)NS * SP)-SC)-(((double)NS * PP) + PC); return result; } void warning() { cout << "Amount must be greater than 0.00 USD.\n"; }``````

The error says the following.
 ``123`` ``````p374p19.cpp: In function ‘int main()’: p374p19.cpp:82:55: error: too many arguments to function ‘double profit()’ p374p19.cpp:35:8: note: declared here``````

I am confused because there are 5 arguments and 5 parameters??
Last edited on
 I keep getting an error for the following program.

What error? If you get a compile error post the complete error message exactly as it appears in your development environment. Otherwise please as specific questions, and throughly describe the problem
I apologize, I have been doing google searches on it all day and it slipped my mind. I have edited my original post
 ``1234`` ``````double profit(); ... double profit(int NS, double SP, double SC, double PP, double PC) {``````

They must agree.
Just learning so most likely I'm wrong but your function prototype is

 ``12`` ``````// Function prototypes double profit();``````

Should that be:

 ``12`` ``````// Function prototypes double profit(double d1, double d2, double d3, double d4, double d5);``````
?
Thank you jib... I just changed it to be double profit (int,double,double,double,double) and that fixed it.
Topic archived. No new replies allowed.