Desperately need help with this Program, can anyone help?

Hello, I am a MIS major and unfortunately one of the major requirements is that I have to take a programming class. I am terrible at programming, all I need to do is get through this class to graduate. Below is the assignment that I have to do, and below that is what I've already tried to do, if anyone can help me you would be saving my ass. thank you

Please enter a candidate (enter done to stop)
Thomas
Enter the number of votes Thomas recieved
456
Please enter a candidate (enter done to stop)
Imelda
Enter the number of votes Imelda recieved
5467
Please enter a candidate (enter done to stop)
Leo
Enter the number of votes Leo recieved
3454
Please enter a candidate (enter done to stop)
Maria
Enter the number of votes Maria recieved
986
Please enter a candidate (enter done to stop)
done

Candidate Votes % of Total Votes
Thomas 456 4.40027
Imelda 5467 52.755
Leo 3454 33.3301
Maria 986 9.51462

--------that is what is suppose to look like, but below is all I have so far-----------

#include

char candidate ();
int takevotes ();
int printvotes();
const int MAX_CANDIDATES=5

int main (){

string candidates [MAX_CANDIDATES];
int votes [MAX_CANDIDATES]
takevotes (votes):
printvotes (candidate, votes);
}

void candidate(string cand_list []){

string candidates [MAX_CANDIDATES];
for(int i=0, i< MAX_CANDIDATES; i++){
cout << Please enter a candidate (enter done to stop) << endl;
cin>> candidate [i]; }

calc takevotes (votes, MAX_CANDIDATES);
}


void takevotes (int getvotes [ ], int size ) {
float votes [ MAX_CANDIDATES];
for(int v=0, v< MAX_CANDIDATES; v++){
cout << Enter the number of votes recieved << endl;
cin>> votes [v]; }


printvotes(allvotes, size);}


void printvotes(float allvotes [ ], int size ) {

float total = 0;
for (x=0; x< size; x++) {
total= total + allvotes [ x ];
cout<< "Candidates" << setw(10) << "Votes" << setw(10) << "% of Votes" << endl;

cout<< candidate << setw(10) << votes << setw(10);
float oneArray [ 0 ] = total/oneArray [ 0 ];
cout<< float oneArray [ 0 ] << endl;

cout<< candidate << setw(10) << votes << setw(10);
float oneArray [ 1 ] = total/oneArray [ 1 ];
cout<< float oneArray [ 0 ] << endl;

cout<< candidate << setw(10) << votes << setw(10);
float oneArray [ 2 ] = total/oneArray [ 2 ];
cout<< float oneArray [ 0 ] << endl;

cout<< candidate << setw(10) << votes << setw(10);
float oneArray [ 3 ] = total/oneArray [ 3 ];
cout<< float oneArray [ 0 ] << endl;

cout<< candidate << setw(10) << votes << setw(10);
float oneArray [ 4 ] = total/oneArray [ 4 ];
cout<< float oneArray [ 0 ] << endl;}


Comments

  • Perhaps you should post it on the C++ board, instead of the C++ Builder board? Or do you want to display the results in a TWin64AdvancedRichEdit Component?
    bilderbikkel

  • [b][red]This message was edited by bilderbikkel at 2005-9-19 2:13:17[/red][/b][hr]
    [b][red]This message was edited by bilderbikkel at 2005-9-19 1:6:25[/red][/b][hr]
    : const int MAX_CANDIDATES=5
    Don't forget the comma after this line!

    : int main (){
    It should be 'int main(int argc, char* argv[]) {'
    (See www.codepedia.com/1/CppMain), also main should 'return 0;' in the end

    : string candidates [MAX_CANDIDATES];
    Do not forget to #include (See www.codepedia.com/1/CppString)
    Do not forget to either use 'std::string candidates' or to write 'using namespace std;' on top

    : for(int i=0, i< MAX_CANDIDATES; i++){
    For loops statements are seperated by ; (instead of the comma after int i=0 )

    : int votes [MAX_CANDIDATES]
    Prefer a std::vector over an array
    (See www.codepedia.com/1/CppVector)

    : calc takevotes (votes, MAX_CANDIDATES);
    This is nonsense, what does 'calc' do? I guess you should remove it.


    bilderbikkel





Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion