Record Type:

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
#include <iostream> 
#include <string>
#include <math.h>
#include <iomanip>
using namespace std; 

struct purchaseType
{
	string invoiceID;
	double salesAmt;
	double totalAmt;
};

	double computeTotal(double);
	void displayRecords();

	string invoiceNum;
	const int maxRecord = 20;
	double salesNum, totalNum;

int main() 
{	
	purchaseType purchaseTable[maxRecord] = {
											{"B0707211",120.50,126.50 },
											{"Q0503412",80.00, 84.00},
											{"W0805015",139.98, 146.90},
											}; 

	cout << "Enter Sales Amount: ";
	cin >> purchaseTable[4].invoiceID ;

	cout << "Enter Sales Amount: ";
	cin >> purchaseTable[4].salesAmt;

	computeTotal(purchaseTable[4].salesAmt);
	displayRecords();

	cin.ignore();
	cin.ignore();
}

double computeTotal(double salesAmt)
{
	double Total;
	Total = salesAmt + 0.05*salesAmt;
	Total =	floor(Total*10.0)/10.0;
	return Total;
}

void displayRecords()
{
	for (int i = 0; i < maxRecord; i++)
	{
		double num;
		num = computeTotal(purchaseTable[i].salesAmt);
		purchaseTable[i].totalAmt = floor(num*10.0)/10.0;
		cout << fixed << setprecision(2) << "Sales Amount: " 
			<< purchaseTable[i].salesAmt << " and Total Amount: " 
			<< purchaseTable[i].totalAmt << endl;	}
}
Last edited on
Where is the problem with that?

Please use [code][/code] tags when posting code

(Fixed)


purchaseTable wasn't declared in the scope of displayRecords.
That could be fixed by having that function getting as argument a purchaseType*: void displayRecords(purchaseType *purchaseTable) and remember to pass purchaseTable in main
Last edited on
line 55:
binary '[' : 'purchaseType' does not define this operator or a conversion to a type acceptable to the predefined operator
and
left of '.salesAmt' must have class/struct/union

line 56:
binary '[' : 'purchaseType' does not define this operator or a conversion to a type acceptable to the predefined operator
and
left of '.totalAmt' must have class/struct/union

line 58:
binary '[' : 'purchaseType' does not define this operator or a conversion to a type acceptable to the predefined operator
and
left of '.salesAmt' must have class/struct/union

line 59:
binary '[' : 'purchaseType' does not define this operator or a conversion to a type acceptable to the predefined operator
and
left of '.totalAmt' must have class/struct/union


i have done some read and even change the code to:
1
2
3
4
5
6
7
8
9
10
11
12
void displayRecords(purchaseType tempTable)
{
	for (int i = 0; i < maxRecord; i++)
	{
		double num;
		num = computeTotal(tempTable[i].salesAmt);
		tempTable[i].totalAmt = floor(num*10.0)/10.0;
		cout << fixed << setprecision(2) << "Sales Amount: " 
			<< tempTable[i].salesAmt << " and Total Amount: " 
			<< tempTable[i].totalAmt << endl;
	}
}


the error is this there..
Last edited on
I was editing my post above, try reading it again
how to i pass purchaseTable in main?

Could u explain to me why?
void displayRecords(purchaseType *purchaseTable)
i am assigning the 5th record of purchaseTable with invoice and sales input, my total is invoke the function computetotal.
You should use a pointer as argument type if you are passing an array.
You can pass purchaseTable as any other argument displayRecords( purchaseTable );
 
displayRecords( purchaseTable );


error:
'displayRecords' : cannot convert parameter 1 from 'purchaseType [20]' to 'purchaseType &'
Have you edited the displayRecords declaration to take a purchaseType* argument?
Yup, i did it as was told by u..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

displayRecords( purchaseTable );



void displayRecords(purchaseType *purchaseTable)
{
	for (int i = 0; i < maxRecord; i++)
	{
		double num;
		num = computeTotal(purchaseTable[i].salesAmt);
		purchaseTable[i].totalAmt = floor(num*10.0)/10.0;
		cout << fixed << setprecision(2) << "Sales Amount: " 
			<< purchaseTable[i].salesAmt << " and Total Amount: " 
			<< purchaseTable[i].totalAmt << endl;
	}
}
Last edited on
I mean the forward declaration you had on line 15
1
2
 
void displayRecords(purchaseType );
void displayRecords(purchaseType*);
You need a pointer argument
what the different between & and using *??
& = reference = the argument becomes the variable you are passing
* = pointer = the argument holds a position in memory

http://www.cplusplus.com/doc/tutorial/functions2.html
http://www.cplusplus.com/doc/tutorial/pointers.html
Topic archived. No new replies allowed.