Writing a function with void paramter

For my assignment I have to do use a previous assignment I did and break it into the following functions:

// get the number of rows from the user, assuring legal and odd,
// then return it to the caller
int GetNRows( void );

There are others I have to write a functions that I need to write for this problem, but I'm really stuck on this first function. When I compile it I get an error that says: "error: expected primary-expression before 'int'" and "error: expected ';' before 'int'" I'm not really sure if I'm approaching this correctly or not. Thank you in advance for your help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  #include<iostream>
using namespace std;

int GetNRows()
{
    int nRows;
    cout << "Enter nRows: " << flush;
    cin >> nRows;
    return nRows;
}
int main()
{
    int nRows;
    nRows=int GetNRows();
    return 0;
}
Last edited on
nRows =int GetNRows();
when you call a function you dont need to include its type
Also I forgot to mention that inside where you put the parameters it is void so it's int GetNRows(void) also if I return it to caller where should I return it?
void parameter means no parameters.

int GetNRows() thats already a void parameter.

void = nothing. Just change this nRows=int GetNRows(); to this nRows = getNRows();

And your function is done. You are already returning rows. return nRows;

And saving it in nRows back in main.
closed account (SECMoG1T)
And just to mention type function(void) are mostly used for backward compatibility with 'C' language so they maybe necessary if Op want's to maintain that but not required in plain c++.
Last edited on
If it's okay, I sent you(andy1992) a PM of my program and I'm hoping you can look at it when you get the chance. Thanks for the advice! Sorry for the disturbance.
Topic archived. No new replies allowed.