help with c++ 1 reply

Please wait...

The_Computer_Wizard

The Force is strong with him

50 XP

10th September 2006

0 Uploads

321 Posts

0 Threads

#1 10 years ago

ok, someone please help me because my brain hurts

im here on thanksgiving vacation and i need to write a program for my class, although i have one problem.

the program i have to write is an electronic voting program, and right now im not even trying to write it secure (meaning it would be easily hackable but i just want it working, then i'll secure it)

im trying to write a function, but im having a problem, see my teacher wants us to read in from a file that looks like this (things in () are not in the file)

3 (number of positions) President (position title) 4 (how many are running) 1 (how many people you can vote for) Abraham lincoln (person running) George Washington (person running) JFK (person running) FDR (person running) Senator (next position title) 2 (how many are running) ....

and so on for the rest of the file

now she wants us to write the program so that she can edit how many people are in each race, or how many positions there are people running for

How i was thinking about accomplishing this was with several arrays such that

fstream file; file.open ("BALLOTQUESTIONS.txt");

int num_positions; file>> num_positions;

string candidate_title[num_positions];

file>>candidate_title[0];

int num_candidates[num_positions]; file>>num_candidates[0];

int numvotes[num_positions]; string candidates[num_positions][num_candidates[num_positions]];

int x=0; int y=0;

file.close();

file.open ("BALLOTQUESTIONS.txt"); file>>num_positions;

while (!(x==num_positions)) { file>>candidate_title[x]; file>>num_candidates[x]; file>>numvotes[x]; while (!(y=num_positions)) { file>>candidates[x][y]; y++; }

x++; }

return (num_positions, candidate_title[num_positions], num_candidates[num_positions], numvotes[num_positions], candidates[num_positions][num_candidates]) }

now no matter what i do i cant return the values of these arrays out of the function!! and its pissing me off!!! Also if some of my logic is wrong its not that big a deal, i can work through that, but why cant i return the values of the arrays, or any way of getting all the values out into other functions (which need to print the candidates names, and needs to know how many votes the user can make for each position)

someone please help me! considering this is only about 1/3 of the program i have to write and im stuck on it




War Hawk

۞ www.thisisnotporn.com ۞

50 XP

27th January 2004

0 Uploads

8,749 Posts

0 Threads

#2 10 years ago

You forgot the second equal sign in your final while loop. Dunno if that will help it return the value of the arrays or not, but it's still an error :p

Also, it might be easier to make a structure instead of having all of those arrays flying around.