Click here to Skip to main content
15,891,846 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My function calls for createBox and fillBox are giving me errors. How can I fix this problem?
C++
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;

void fillBox(int magicbox[19][19], int n);
void createBox(int magicbox[19][19], int n);

ofstream outfile;
int main()
{
	outfile.open("output.txt");
	int magicnumber; //intermediate variable
	createBox();
	fillBox();
	outfile << "Welcome to  the Magic Square Program!" << endl << endl;
	cout << "Welcome to  the Magic Square Program!" << endl << endl;
	
	cout << "Enter an odd number: ";
	cin >> magicnumber;
	outfile << "Number user entered: " << magicnumber << endl;

	if (magicnumber % 2 == 0){
		do{ //this loop only allows the user to input odd integers
			cout << "Please input odd integers only: " << endl;
			cin >> magicnumber;
		} while (magicnumber %  2 == 0);
	}
	cout << "Magic Box#: " << " > " << magicnumber << " <" << endl << endl;
	outfile << "Magic Box#: " << " > " << magicnumber << " <" << endl << endl;

	system("pause");
	return 0;
}
void createBox(int magicbox[19][19], int n){
	for (int i = 0; i <(n*n); i++){
		for (int x = 0; x < n; x++){
			for (int y = 0; y<n; y++){
				cout << magicbox[x][y];
			}
		}
		cout << endl;
	}
}
Posted
Updated 24-Feb-15 20:24pm
v2
Comments
_Asif_ 25-Feb-15 2:25am    
What kind of errors are you getting? Where is the code of fillbox?
enhzflep 25-Feb-15 2:28am    
By passing variables to them.
Each of their signatures indicate that they expect:
1. a 2d array of 19 x 19 elements
2. an integer.

You're not passing either of these.

Trying to compile your code with MinGW results in the following errors:
Clearly, line 14 and line 15 are the errors - you're also told what the problem is.


||=== Build: Debug in 001-forumQuestion (compiler: GNU GCC Compiler) ===|
D:\code\001-forumQuestion\main.cpp||In function 'int main()':|
D:\code\001-forumQuestion\main.cpp|14|error: too few arguments to function 'void createBox(int (*)[19], int)'|
D:\code\001-forumQuestion\main.cpp|7|note: declared here|
D:\code\001-forumQuestion\main.cpp|15|error: too few arguments to function 'void fillBox(int (*)[19], int)'|
D:\code\001-forumQuestion\main.cpp|6|note: declared here|
D:\code\001-forumQuestion\main.cpp|32|error: 'system' was not declared in this scope|
||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

Because you have declared then as taking parameters:
C#
void fillBox(int magicbox[19][19], int n);
void createBox(int magicbox[19][19], int n);

And then called them without supplying the parameters:
C#
createBox();
fillBox();
You need to declare the array somewhere, and pass that, and presumably pass the size of each array dimension as the second parameter.
 
Share this answer
 
This is the sixth time you have posted what is effectively the same question, and you seem to be going nowhere. I suggest you go back to your study guides, or search for some tutorials, and work on understanding the basics of C++. This is not a particularly difficult assignment, but you do need to understand the structure of the language. Repeatedly posting you latest guesswork is not the best way to learn.
 
Share this answer
 
Comments
Stefan_Lang 25-Feb-15 5:24am    
Indeed, I have posted pretty much the same in a different thread. Have a 5, just to drive the point home ;-)
Richard MacCutchan 25-Feb-15 5:34am    
Thanks, but I think we may need a hammer. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900