Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 05-13-2010, 09:45 PM   #11
Baseband Member
 
thevil1's Avatar
 
Join Date: Dec 2009
Posts: 36
Default Re: C++, I'm stuck with vectors and functions

Well Can I cut in with my owns question?

OK so I have a new question. Unless you know a bit about programming you probably wont be able to help, But you can still say what you think.
I'm trying to make a console program of the math game Suduku, in C++. I have the algorithm wrote out, but then syntax is a problem for me. This is what I have so far:
Code:
//By: Thevil1
#include <iostream>                                                     //line 1
using namespace std;                                                    //line 2
int main()                                                              //line 3

{                                                                       //line 4
    int aa, ab, ac, ad, ae, af, ag, ah, ai,                             //line 5
        ba, bb, bc, bd, be, bf, bg, bh, bi,                             //line 6
        ca, cb, cc, cd, ce, cf, cg, ch, ci,                             //line 7
        da, db, dc, dd, de, df, dg, dh, di,                             //line 8
        ea, eb, ec, ed, ee, ef, eg, eh, ei,                             //line 9
        fa, fb, fc, fd, fe, ff, fg, fh, fi,                             //line 10
        ga, gb, gc, gd, ge, gf, gg, gh, gi,                             //line 11
        ha, hb, hc, hd, he, hf, hg, hh, hi,                             //line 12
        ia, ib, ic, id, ie, iF, ig, ih, ii;                             //line 13
ab = 3; ad = 1; ae = 7; ai = 4;  bd = 9; bf = 8; bg = 6; cc = 7; ce = 2;//line 14
ch = 8; ci = 5; dd = 7; dg = 8; di = 2; ea = 5; ec = 8; ed = 6; ef = 2; //line 15
eg = 7; ei = 1; fa = 1; fc = 2; ff = 5; ga = 7; gb = 8; ge = 4; gg = 3; //line 16
hc = 3; hd = 2; hf = 1; ia = 4; ie = 6; iF = 7; ih = 1;                 //line 17


  
    //board game layout
    cout << "|_1___2___3_|_4___5___6|__7___8___9_|  \n";                //line 18
    cout << "|   |   |   |   |   |   |   |   |   |  \n";                //line 19
    cout << "|___|___|___|___|___|___|___|___|___|a \n";                //line 20
    cout << "|   |   |   |   |   |   |   |   |   |  \n";                //line 21
    cout << "|___|___|___|___|___|___|___|___|___|b \n";                //line 22
    cout << "|   |   |   |   |   |   |   |   |   |  \n";                //line 23
    cout << "|___|___|___|___|___|___|___|___|___|c_\n";                //line 24
    cout << "|   |   |   |   |   |   |   |   |   |  \n";                //line 25
    cout << "|___|___|___|___|___|___|___|___|___|d \n";                //line 26
    cout << "|   |   |   |   |   |   |   |   |   |  \n";                //line 27
    cout << "|___|___|___|___|___|___|___|___|___|e \n";                //line 28
    cout << "|   |   |   |   |   |   |   |   |   |  \n";                //line 29
    cout << "|___|___|___|___|___|___|___|___|___|f_\n";                //line 30
    cout << "|   |   |   |   |   |   |   |   |   |  \n";                //line 31
    cout << "|___|___|___|___|___|___|___|___|___|g \n";                //line 32
    cout << "|   |   |   |   |   |   |   |   |   |  \n";                //line 33
    cout << "|___|___|___|___|___|___|___|___|___|h \n";                //line 34
    cout << "|   |   |   |   |   |   |   |   |   |  \n";                //line 35
    cout << "|___|___|___|___|___|___|___|___|___|i_\n";                //line 36
    cout << endl;                                                       
    
       
system("pause");                                                        //line 37                                  
return 0;                                                               //line 38                         
}                                                                       //line 39
I copied a puzzle from websudoku.com. My problem is How do I get the pre-defined integers (lines 14-17) into their correct place on the bored, an the one that are user defined into their correct places. Then I will just use one big 'if' statement to sum it all up.

NOTE: the board layout goes as follows:
'aa' goes in 1a, 'ab' goes in 2a etc... I tried to make it as simple as I could.
PLEASE HELP!
__________________

__________________
An optimist is someone who falls off the Empire State Building, and after 50 floors says, ''So far so good!''
thevil1 is offline   Reply With Quote
Old 05-15-2010, 12:36 PM   #12
Site Team
 
berry120's Avatar
 
Join Date: Jul 2009
Location: England, UK
Posts: 3,425
Default Re: C++, I'm stuck with vectors and functions

Quote:
NOTE: the board layout goes as follows:
'aa' goes in 1a, 'ab' goes in 2a etc... I tried to make it as simple as I could.
Geez... Go look up arrays! (Specifically, 2D ones!)
__________________

__________________
Save the whales, feed the hungry, free the mallocs.
berry120 is offline   Reply With Quote
Old 06-04-2010, 03:57 AM   #13
Daemon Poster
 
RewtGuy's Avatar
 
Join Date: Dec 2004
Posts: 595
Send a message via AIM to RewtGuy
Default Re: C++, I'm stuck with vectors and functions

Sudoku guy, Might want to write a function to draw your board.
__________________
Windows: A thirty-two bit extension and GUI shell to a sixteen bit patch to an eight bit operating system originally coded for a four bit microprocessor and sold by a two-bit company that can't stand one bit of competition.
RewtGuy is offline   Reply With Quote
Old 06-11-2010, 03:45 PM   #14
In Runtime
 
Join Date: Dec 2007
Posts: 195
Default Re: C++, I'm stuck with vectors and functions

Not sure about in C++, and if they behave the same way but this is how you would do it in java.

Code:
//java
Vector<datatype> vector_name = new Vector<datatype>();
vector_name.add(new datatype(arg1, arg2, arg3));
So if I were you I'de make sure that my turbine class has a constructor defined (post your turbine.h file so we can help with this).

Then, perhaps something like this will work:
Code:
//c++
Vector <turbine> turb();
turb.push_back(new turbine(arg1, arg2, arg3)); //constructor arguments
or alternatively with code that's a little easier to understand you could use
Code:
//c++
Vector<turbine> turb();
turbine tmp = new turbine(arg1, arg2, arg3); //construstor arguments
turb.push_back(tmp);
Post your turbine.h file and we'll be able to help out more.

Edit: Nvm I see your turbine file now, but not the code of the turbine constructor, just it's declaration. I think the problem may be in there. Keep in mind you can use the constructor to set initial values of your turbines rather than calling gets and sets for each newly created turbine.
__________________

colorblindjimbo is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 11:38 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0