为什么我在魔术方程序中的数组中出错? [英] Why I'm I getting an error in my array for my magic square program?
本文介绍了为什么我在魔术方程序中的数组中出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在源代码底部附近的[m]和[0]下面出现红色波浪线
#include<的iostream>
#include< fstream>
#include< iomanip>
using namespace std;
void CreateSquare(int& n); //创建Magic Square的函数
int main(){
ofstream outfile;
ifstream infile;
outfile.open(output.txt);
infile.open(numbers.txt);
int row,col;
cout<< 输入魔盒的顺序:;
int n = 5;
int ms = n * n;
int MagicSquare;
int分类;
cin>>分类;
if(分类%2 == 0){//分类奇数或甚至
cout<< 请输入奇数整数:;
}
int m = n / 2,s = n-1;
for(int i = 1; i< = ms; i ++){
cout>>幻方[米] [s]的;
cout>> MagicSquare [0] [2] = 1; //将数字1放在顶行中间列
m ++;
s--;
}
for(int row = 0; row< n; row ++){
for(int col = 0; col< n; col--)
{
cout<<幻方[米] [s]的;
}
}
system(暂停);
返回0;
}
解决方案
可能因为 int MagicSquare
不是阵列
I keep getting red squiggly lines under my [m] and [0] near the bottom of the source code
#include<iostream> #include<fstream> #include<iomanip> using namespace std; void CreateSquare(int&n); //function to create Magic Square int main(){ ofstream outfile; ifstream infile; outfile.open("output.txt"); infile.open("numbers.txt"); int row, col; cout << "Enter order of the magic box: "; int n = 5; int ms = n * n; int MagicSquare; int classification; cin >> classification; if (classification % 2 == 0){ //classification odd or even cout << "Please enter odd integers only: "; } int m = n/2, s = n-1; for (int i = 1; i <= ms; i++){ cout >> MagicSquare[m][s]; cout >> MagicSquare[0][2] = 1; //Putting the number 1 in top row middle column m++; s--; } for (int row = 0; row < n; row++){ for (int col = 0; col < n; col--) { cout << MagicSquare[m][s]; } } system("pause"); return 0; }
解决方案
Maybe because int MagicSquare
isn't an array?
这篇关于为什么我在魔术方程序中的数组中出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文