为什么编译器会忽略我的void函数? [英] Why is the compiler ignoring my void function?

查看:87
本文介绍了为什么编译器会忽略我的void函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的void函数中获取一些行和列来打印,但它不起作用,我不知道为什么。我正在制作一个Magic Square节目。我真的要放弃计算机科学。



I'm trying to get some rows and columns to print from my void function, but it's not working and I don't know why. I'm making a Magic Square program. I'm really about to give up computer science.

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

推荐答案

它不会忽略你的 void createBox(int magicbox [ 19] [19],int n)功能。

你根本就没有调用这个功能。



main 函数是一种特殊情况,因为此函数 由程序外部的代码调用。但是, createBox 就像任何其他函数一样。如果您想使用它,您必须打电话给它。你没有这样做,所以这个功能永远不会执行。



你的问题类似于坐在餐馆里,想知道为什么你没有吃牛肉,事实上,你从未真正订购它。
It's not ignoring your void createBox(int magicbox[19][19], int n) function at all.
You are simply not calling the function.

The main function is a special case, since this function is called by code external to your program. However, createBox is just like any other function. If you wish to use it, you must call it. You haven't done so, so the function never executes.

Your question is similar to sitting in a restaurant and wondering why you weren't served the beef, when in fact, you never actually ordered it.


根据这个以及之前的问题判断,你需要了解如何编程的大量帮助。如果你真的想学习,那就是。



不要以为你可以在一天甚至一周内学习编程!只是为了得到基础知识,你需要几个星期,只有这样你才能写出一个魔术方案(和其他许多人) - 但不是很好:你可能仍然需要一些帮助。< br $> b $ b

我们为您在计划中遇到的每一个问题提供建议是没有意义的:如果我们这样做了,您就会遵循我们所有的个人建议,完成你的计划仍需要数周时间。你的程序中仍有很多问题你甚至都没有认识到。你可以花更多的时间来完成一两个基本教程,例如: g。:

http://www.cplusplus.com/doc/tutorial/ [ ^ ]

http://www.cprogramming.com/tutorial/c++-tutorial.html [ ^ ]
Judging by this and your previous questions you need a whole lot of help understanding how to program. If you really want to learn, that is.

Do not assume that you can learn programming within a day, or even a week! Just to get the basics, you will need a couple of weeks, and only then will you be able to write a magic squares program (and many others) - but not very well: you will likely still need some help here and there.

It won't make sense for us to provide advice for every single issue you are encountering in your program: if we did that, and you follow all of our individual advices, it will still take weeks to finish your program. There are still a lot of issues in your program that you didn't even recognize yet. You would do better to spend that time working through a basic tutorial or two, e. g.:
http://www.cplusplus.com/doc/tutorial/[^]
http://www.cprogramming.com/tutorial/c++-tutorial.html[^]


这篇关于为什么编译器会忽略我的void函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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