need help with my homework.

closed account (N8bDjE8b)
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!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
   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 <iostream>
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.
1
2
3
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
closed account (N8bDjE8b)
I apologize, I have been doing google searches on it all day and it slipped my mind. I have edited my original post
Your function prototype doesn't agree with your function implementation:
1
2
3
4
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

1
2
// Function prototypes
double profit();


Should that be:

1
2
// Function prototypes
double profit(double d1, double d2, double d3, double d4, double d5);
?
closed account (N8bDjE8b)
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.