C++ Help? Functions

pathfinder

New Member
So I am working on this assignment for school and having a strange issue.
I would, ofc, rather use a different function for every question to get the user input separately, however my professor is requiring we use a 'void' function to retrieve several inputs (I think this is called 'pass by reference').

That actually is not giving an error code, but the output.cpp file is! Strange..


This is the declaration of the function, above 'int main()':
PHP:
void   OutputInvoice (int    accountNumber   ,  
                      string countyName      ,
                      int    dateDay         ,
                      int    dateMonth       ,
                      int    dateYear        ,
                      float  initialSale     ,
                      float  discount        ,
                      float  salesTax        ,
                      float  shippingCost    ,
                      float  saleAmount     );

The header (or definition?) of the actual code (WHERE THE ERROR IS):
PHP:
OutputInvoice (accountNumber   ,  
               countyName      ,
                      int    dateDay         ,
                      int    dateMonth       ,
                      int    dateYear        ,
                      float  initialSale     ,
                      float  discount        ,
                      float  salesTax        ,
                      float  shippingCost    ,
                      float  saleAmount     );


Next is the code to call the function:

PHP:
OutputInvoice (accountNumber   ,  
               countyName      ,
                      int    dateDay         ,
                      int    dateMonth       ,
                      int    dateYear        ,
                      float  initialSale     ,
                      float  discount        ,
                      float  salesTax        ,
                      float  shippingCost    ,
                      float  saleAmount     );

And finally, the actual function itself, along with a verbatim copy of the error I am receiving. Also I am using Netbeans with mingw if that is relevant.

PHP:
{
cout << left;
cout << setw(20) << "ACCOUNT NUMBER";
cout << setw(20) << "COUNTY\n";
cout << setw(10) << accountNumber;
cout << setw(20) << countyName << endl;

cout << "DATE OF SALE: ";
cout << dateMonth << "/" << dateDay << "/" << cout << dateYear;
cout << endl << endl << endl << endl;

cout << setw(20) << "$" << setprecision(3);
cout << initialSale;

}

THE ERROR CODE when trying to compile:
PHP:
error: expected primary-expression before 'int'
It says this for every line I posted in the second box.

Now, I have tried switching things all over the place--including adding the data type before each variable--but I'm new to functions (and CPP in general) so if anyone can shed some light here, it would be greatly appreciated.
 
Last edited:
When you actually call the function, you don't include the data types, just the variables. I don't know if that's giving you the error or not, but I did notice that.
And as a suggestion for the future. It is better if the argument you use in the function call has a different variable name than the function definition. It won't always cause problems, but it can.

As far as what's actually wrong, the error should give you the line that the error occurs on. Can you give us that line??
 
Ah--I forgot to take out the data types, as I added them for my original error-message to see if it would fix the problem.
I corrected it and will post the true issue:

This is the entire source file:
Code:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

/********************************
*function to display all output *
*********************************/
[I]void OutputInvoice (accountNumber   ,  
                    countyName      ,
                    dateDay         ,
                    dateMonth       ,
                    dateYear        ,
                    initialSale     ,
                    discount        ,
                    salesTax        ,
                    shippingCost    ,
                    saleAmount      )[/I]
{
cout << left;
cout << setw(20) << "ACCOUNT NUMBER";
cout << setw(20) << "COUNTY\n";
cout << setw(10) << accountNumber;
cout << setw(20) << countyName << endl;



}

Not seeing an option for code lines, so I put the lines in italics with the following error, there are 2:

error: variable or field 'OutputInvoice' declared void

error: 'accountNumber' was not declared in this scope
(the second error code is the same for all the italicized lines, as where the top error is only for the 'void OutputInvoice (accountNumber.. . line
 
No, no. In the function definition (what you just posted) you do need the data types preceding the variables.

When you actually call the function, you don't include the data types. So do that, run it again, then post those error message and which lines they are.
 
I think that solved the problem. At least now it's giving different error codes for different source files.
Thank you for the help! =)
 
Back
Top