"cannot convert from type void to int"

I am trying to write this program with two functions but I keep getting the compiling error "cannot convert parameter 2 from 'void' to 'int'. I do know what this means but unfortunately I do not know how to remedy it. I've pasted the code below and if anyone can help me out, that would be excellent.

#include <fstream>
using namespace std;

ofstream fout;
ifstream fin;

void line(char ch, int num)
{
int i=0;
while(i<=num)
{
i++;
fout << ch;
}
return;
}

void rectangle(char ch, int x, int y)
{
int i=0;
while(i<=y)
{
i++;
fout << x << "\n";
}
return;
}

void main( )
{
char ch;
int i=0,num;

fin.open("Animals.dat");
fout.open("Animals2.dat");
fin.get(ch);
num=ch;

while(!fin.eof())
{
if(ch=='\n')
{
fout << "\n\n\n\n";
i=0;
}
else
{
i++;
fout << rectangle(ch,line(ch,num),i) << endl << endl;
}
fin.get(ch);
}
}
You're asking a void function to return a parameter required for another function in your last fout statement.

1
2
3
fout << rectangle(ch,line(ch,num),i) << endl << endl;

void rectangle(char ch, int x, int y)


You need to either make void line(...); a value returning function, or figure out another way to pass the desired variable.
Last edited on
Also, as a bit of advice:

Do not include "return;" in void functions.
Also, "int main()", not "void main()".
Topic archived. No new replies allowed.