error 31 invalid types `unsigned ***[int]' for array subscript

Hi all - Just getting an error in regards my arrays. Just wondering if I could get some feedback on if they are either done correctly, or if I have made a mistake along the line? Thanks!

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
    #include <iostream>
        #include <iomanip>
        #include <cmath>
        #include <string>
        using namespace std;
         
        int readSaleRecord(unsigned&, double&, char&, unsigned&, double&);
        double calculateItemCost(double itemPrice, double& totalCost, char discountType, unsigned quantity);
        void displayTotalCost(double totalCost, unsigned Num, bool aborted);
        int addRecord(unsigned allIDs[], double allPrices[], char allDiscounts[], unsigned allQuantities[], int &totalRec);
       
         
        int main()
        {
         unsigned itemId, quantity, records, num, allIDs, allQuantities;
         double itemPrice, totalCost, discount, recordNum, allPrices;
         char discountType, allDiscounts;
         bool aborted=false, ItemDetails;
         int totalRec, i, j=0;
        
 	for(i=0;i<100;i++){
	        readSaleRecord(itemId, itemPrice, discountType, quantity, recordNum);  
		if(true == 1){
                   calculateItemCost(itemPrice, totalCost, discountType, quantity);
                   displayTotalCost(totalCost, num, aborted);}      
        	calculateItemCost(itemPrice, totalCost, discountType, quantity);          
	        displayTotalCost(totalCost, num, aborted);
         }
         
// probably don't need this
 addRecord (allIDs[10], allPrices[10], allDiscounts[10], allQuantities[10], totalRec[10]);{
		allIDs[i] = itemId;
		allPrices[i] = itemPrice;
		allDiscounts[i] = discountType;
		allQuantities[i] = quantity;
		allCosts[i] = totalCost; 
		totalRec = totalRec + totalCost; 
}



The errors I am getting is 'unsigned ****[int]' for array subscirpt.

Thanks in advance!
Last edited on
Are you double-posting under a different name? This looks suspiciously similar code to something I've just answered in the general forum.

Could be something to do with declaring single variables instead of arrays.
Nope? This is my first account on this website. This is from a University assignment so I guess maybe someone else has come across the same problem possibly? I'm not too sure.

addRecord (allIDs[10], allPrices[10], allDiscounts[10], allQuantities[10], totalRec[10]);{

If this is meant to be the start of a function definition, that semi-colon has no business being there, but you're missing the types of the parameters. The first line of a function definition should look like the prototype.

Since you made allIDs a single unsigned int value, that you later use the same name here but indicate that it should be some kind of array, indicates that you haven't thought enough about what you're trying to do and what the variables should be.
Last edited on
addRecord (allIDs[], allPrices[], allDiscounts[], allQuantities[], totalRec[])

I've changed that part of the code accordingly to match my function.

Though now I get an error:
"Expected primary-expression before ']' token"

Is the addRecord at the bottom supposed to be the function definition?

If so, there are a few problems with it.
Yeah, that was supposed to be the function definition / function header. I was under the impression that the function headers had to be the same as the function prototype regardless?
Whup. Missed a post.
Last edited on
Oh, I fixed that up a few replies ago so that it now reads correctly as the same. I had tried that earlier but forgotten to change those 10's back to the closed square brackets.
The function declaration and definition need to match up, yeah.

If your delcaration, for example, is:
 
int addRecord(unsigned allIDs[], int &totalRec);


Then your definition would be written like so:
1
2
3
4
int addRecord(unsigned allIDs[], int &totalRec)
{
   // Whatever you want the function to do
}


Make sure your definition isn't inside of main().
Okay, so got all that fixed up and working now - Thankyou very much for that!

Though now it is teling me:
"a function-definition is not allowed here before '{' token'
"expected ',' or ';' before '{' token"

Any idea what that could possibly mean?
It means you've got your syntax wrong and you're trying to define your functions in the wrong place. Probably inside other functions.
Sounds like a brace mismatch or a missing semicolon.

In light of Moschops' suggestion, you should keep your program structure simple.

1
2
3
4
// - Includes
// - Function Definitions (Prototypes/Headers/Whatever you want to call them)
// - Main
// - Function Declarations (Or bodies, if you prefer) 
Last edited on
Trying to fix it all up now to make it a bit more simple cause I can definitely see how confusing this would be for someone to just open up and look at!

Thanks heaps for the help everyone. Really apperciate it!
Happens like that a lot with code.

Just try your best to keep it tidy and well commented.

Keep in mind: KISS your code.
(Keep It Simple, Stupid)
Topic archived. No new replies allowed.