为什么我的函数调用不起作用,我收到错误 [英] Why are my function calls not working, I'm receiving errors

查看:79
本文介绍了为什么我的函数调用不起作用,我收到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的函数调用createBox和fillBox给了我错误。我该如何解决这个问题?

  #include   < span class =code-keyword><   iostream  >  
#include < fstream >
#include < iomanip >
使用 命名空间标准;

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; // 中间变量
createBox();
fillBox();
outfile<< 欢迎来到Magic Square计划!<< endl<< ENDL;
cout<< 欢迎来到Magic Square计划!<< endl<< ENDL;

cout<< 输入一个奇数:;
cin>> magicnumber;
outfile<< 输入的数字用户:<< magicnumber<< ENDL;

if (magicnumber% 2 == 0 ){
执行 { // 此循环仅允许用户输入奇数整数
cout<< 请输入奇数整数:<< 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){
< span class =code-keyword> for
int i = 0 ; i< ;(n * n); i ++){
for int x = 0 ; x< n; x ++){
for int y = 0 ; y< n; y ++){
cout<<珠宝盒[X] [Y];
}
}
cout<< ENDL;
}
}

解决方案

因为你已宣布参加参数:

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



然后在不提供参数的情况下调用它们:

 createBox(); 
fillBox();

你需要在某个地方声明数组,并传递它,并且可能会将每个数组维度的大小作为第二个参数传递。


< blockquote>这是你第六次发布有效的同一个问题,而你似乎无处可去。我建议你回到你的学习指南,或者搜索一些教程,并努力理解C ++的基础知识。这不是一项特别困难的任务,但您需要了解该语言的结构。反复发布最新的猜测并不是最好的学习方法。


My function calls for createBox and fillBox are giving me errors. How can I fix this problem?

#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;
	}
}

解决方案

Because you have declared then as taking parameters:

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


And then called them without supplying the parameters:

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.


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.


这篇关于为什么我的函数调用不起作用,我收到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆