Functions part 2

Hello I keep on getting errors with my code.. Here is the scenario:
, there will be 3 functions:
calcMarkUp
calcSalesTax
calcRetailPrice
Each of the function bodies should begin by printing the name of the function.
For example, the first function would print: Inside calcMarkUp

The first function "calcMarkUp" will take 2 arguments: the Wholesale Cost and the Mark Up Rate. It will do the appropriate calculation and return the value of the Mark Up Amount.

The second function "calcSalesTax" will take 3 arguments: the Wholesale Cost, the Mark Up Amount and the Sales Tax Rate. It will do the appropriate calculation and return the value of the Sales Tax Amount.

The third function "calcRetailPrice" will take 3 arguments: the Wholesale Cost, the Mark Up Amount and the Sales Tax Amount. It will do the appropriate calculation and return the value of the Retail Price.

Each of these functions will be called from the function "showResults". After all three of these functions run, "showResults" will print all the input values and calculated results ( I.e. the same thing that the program has been printing all along. )

Run your program with the same values that you used for Lab#7 Part A

And now here is my code:
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//Rebecca Carolina Katz
// Filename:  lab7_b
//Lab 7 part b
//Modifying my code from lab 7 part a to use a function to do each of the calculations involving calcMarkup, 
// calcSalesTax, and calcRetailPrice
#include <iostream>
#include <cmath>
using namespace std;

double calcMarkUp (double, double, double);
double calcSalesTax (double, double,double);
double calcRetailPrice (double, double, double);
double showResults( double,double, double );

int main()
{
	cout << "Rebecca Carolina Katz, Lab 7 part B\n";
	
	// Variable declarations
	double wholesale_cost;
	double Mark_up_percentage;
	double Sales_tax_rate;
    
	char run_the_program_again; 
	

       do 
	   {
	   	
        	// Validating that the wholesale cost is a valid number
	        cout <<"Enter Wholesale Cost:";
	        cin>> wholesale_cost;
        
	        while (wholesale_cost<=0)
	        {
	        	cout<<"Invalid Wholesale Cost must be  a positive number"<< endl;
	        	cout <<"Enter Wholesale Cost:";
	        	cin>> wholesale_cost;
			}
			
			// Validating that the mark up percentage is a valid number
	        cout <<"Enter Mark-up Percentage:";
	        cin>> Mark_up_percentage;
	        
	        while (Mark_up_percentage<=0)
	        {
	        	cout<<"Invalid Mark-up Percentaget must be  a positive number"<< endl;
	        	cout <<"Enter Mark-up Percentage:";
	        	cin>> Mark_up_percentage;
			}
			
			// Validating that the sales tax rate is a valid number
	        cout <<"Enter Sales_tax_rate:";
	        cin>> Sales_tax_rate;
	        
	        while (Sales_tax_rate<=0)
	        {
	        	cout<<"Invalid Sales_tax_rate must be  a positive number"<< endl;
	        	cout <<"Enter  Sales_tax_rate:";
	        	cin>> Sales_tax_rate;
			}
			
			
	        showResults( wholesale_cost, Mark_up_percentage, Sales_tax_rate );
	         
	         cout << "Do you want to run this program again? y or n\n";
	         cin >> run_the_program_again;
	         
       } while (run_the_program_again =='y' || run_the_program_again =='Y' );
       
       cout << "\nGOODBYE\n";
}// end of main

double showResults(double wholesale_cost,  double Mark_up_percentage,  double Sales_tax_rate)
  {

  	//Variable declarations
  	double Mark_Up_Amount;
  	double Sales_Tax_Amount;
  	double Retail_Price;
  	
  	
  	cout << "Inside Show Results\n\n";
  	
  	cout << "WholeSale Cost : " ;
	cout <<  wholesale_cost << endl; 
	
	cout << "\n\nMark Up Percentage : ";
	cout << Mark_up_percentage << endl;
	
	cout << "\n\nSales Tax Rate : ";
	cout << Sales_tax_rate << endl;
  	 
  		Mark_Up_Amount = calcMarkUp(wholesale_cost, Mark_Up_Amount,  );
  	
  	cout << "\n\nMark Up Amount\n" ;
	cout << Mark_Up_Amount << endl;
  	
  	Sales_Tax_Amount = calcSalesTax(wholesale_cost, Mark_Up_Amount, Sales_tax_rate);
  	
  	cout << "\n\nSales Tax Amount\n" ;
	cout << Sales_Tax_Amount << endl;
	
    	Retail_Price = calcRetailPrice(wholesale_cost, Mark_Up_Amount, Sales_Tax_Amount);
  	
  	cout << "\n\nRetail Price Amount\n" ;
	cout << Retail_Price << endl;


}// end of show results
  
double calcMarkUp (double wholesale_cost, double Mark_up_percentage)
{
	//Variable declarations	
	double Mark_Up_Amount;

	Mark_Up_Amount=wholesale_cost*(Mark_up_percentage/100);

	return Mark_Up_Amount;
}
  
  
double calcSalesTax (double wholesale_cost, double Mark_Up_Amount, double Sales_tax_rate)
{
	//Variable declarations	
	double Sales_Tax_Amount;
	Sales_Tax_Amount=(wholesale_cost+Mark_Up_Amount)*(Sales_tax_rate/100);
	return Sales_Tax_Amount;
}

  
double calcRetailPrice(double wholesale_cost, double Mark_Up_Amount,
					double Sales_Tax_Amount)
{
	//Variable declarations
	double Retail_Price;
	Retail_Price=(wholesale_cost+Mark_Up_Amount+Sales_Tax_Amount);
	return Retail_Price;
	
	//  after function calls
	cout << "\n\nInside calcMarkUp\n\n";
    cout << "\n\nInside calcSalesTax\n\n";
    cout << "\n\nInside calcRetailPrice\n\n";
}


I keep getting errors with line 94 (Mark_Up_Amount = calcMarkUp(wholesale_cost, Mark_Up_Amount, );. I do not understand why?
Last edited on
On the line 94 you have a comma and a couple of trailing spaces if you remove the trailing comma and the spaces inside the () then it will run that method with out any problems.

I think this will help you,

Hirokachi
Last edited on
And the errors are? Post the complete error messages, exactly as they appear in your development environment.

for:
Mark_Up_Amount = calcMarkUp(wholesale_cost,Mark_Up_Amount,);

it keeps saying 94 63 C:\Users\Rebecca\OneDrive\Documents\kalzlab7_b.cpp [Error] expected primary-expression before ')' token.

I am using dev c++ if that helps....
and it also says:
10 8 C:\Users\Rebecca\OneDrive\Documents\kalzlab7_b.cpp [Note] declared here
expected primary-expression before ')' token.

What is right before the ')' on that line?

Read Hirokachi's post if you still don't see the problem.
after reading his post it still did not fix the problem. And i dont know what that means. My program doesnt really point out the issues..like i still do not understand what is wrong with:

Mark_Up_Amount = calcMarkUpAmount(wholesale_cost,Mark_Up_Amount);
And what is before the ')' token? Is it a primay-expression? See this link for a definition of primary-expression.

https://msdn.microsoft.com/en-us/library/z94za21a.aspx

By the way that first number in your error message is the line number, the second number is the position within that line where the problem is detected. And when reading your error messages always look for keywords like before or const and many more.

Also when reading and working with error messages you need to start at the first message and work down from there. The order of the messages matter, since fixing the first error/warning may fix multiple following errors. And always provide all of the compile warning/error messages because sometimes later messages can also help identify the actual problem.

If you still can't see the problem read Hirokachi's answer.

i think it said primary expression
Did you read my entire post, and study that link I provided?
Interestingly VC++ 2010 says only synthax error (C2059).

You have declared calcMarkUp as:
double calcMarkUp (double, double, double);

but you call it only with 2 parameters.
calcMarkUp(wholesale_cost,Mark_Up_Amount,);

What the compiler actually tells you is that you are missing a parameter.
Interestingly VC++ 2010 says only synthax error (C2059).

Not really, did you read the documentation for that error? It's really saying the same thing. Every error number the Microsoft compiler produces is quite well documented, when in doubt read the documentation.

https://msdn.microsoft.com/en-us/library/t8xe60cf.aspx
Not really, did you read the documentation for that error? It's really saying the same thing. Every error number the Microsoft compiler produces is quite well documented, when in doubt read the documentation.


No I didn't read it because I had spotted the error already.
Topic archived. No new replies allowed.