Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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.

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
    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 15:03pm
v2
Comments
enhzflep 24-Feb-15 20:44pm    
You've not posted the full code, the question is unlikely to be useful without it.
You'd be wise to edit your question to include it.
PIEBALDconsult 24-Feb-15 21:04pm    
No, he set the pre tag to XML so a bunch got eaten. I've seen that before.
enhzflep 24-Feb-15 21:07pm    
Ahhhh! That makes so many posts in the past make sense. Thanks for the heads-up. :)
PIEBALDconsult 24-Feb-15 21:11pm    
Yeah, one of the first things I do is click Improve question so I can see what was actually posted in case of that.
PIEBALDconsult 24-Feb-15 21:06pm    
I don't see where you call createBox or even define fillBox.

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.
 
Share this answer
 
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[^]
 
Share this answer
 
Comments
Andreas Gieriet 25-Feb-15 10:50am    
My 5!
Cheers
Andi

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