Help me fix this code

Hi, i want to make a Voting system in c++. The idea is that you could write your own party and then people could vote for it. and over and over again. (This code is in Spanish, i'm not very fluent in English)

[code]

#include<iostream>
#include<string>
#include <cstdlib>

using namespace std;
void menu();
void ganador();
float porc(int x);
string pass = "hola";
string input;
void nombre();
string sInput = " ";
string sName1 = " ";
string sName2 = " ";
int iParty1 = 0;
int iParty2 = 0;

int main(int argc, char** argv){
do{
system("cls");
system("color F2");
nombre();



}
while(0==0);
system("cls");
cout<<"Porcentaje de Votos del Primer Candidato: "<<porc(iParty1)<<"%"<<endl;
cout<<"Porcentaje de Votos del Segundo Candidato: "<<porc(iParty2)<<"%"<<endl;
ganador();

return 0;
}


void ganador(){
if(iParty1>iParty2 ){
cout<<"El Ganador es el Primer Candidato"<<endl;
}
if(iParty2>iParty1){
cout<<"El Ganador es el Segundo Candidato"<<endl;
}

if(iParty1==iParty2){
cout<<"Hay un Empate entre los 2 Candidatos"<<endl;
}
}

void nombre(){


cout << "Name del primer partido: ";
cin >> sName1;
cout << "Nombre del segundo partido: ";
cin >> sName2;
cin.ignore();

while (sInput != "")
{
cout << "Su voto: ";
getline(cin, sInput);
cout << endl;
if (sInput == sName1)
{
iParty1++;
}
else
{
if (sInput == sName2)
{
iParty2++;
}
else
{
cout << "Incorrecto" << endl;
}
}

}
cout << sName1 << ": " << iParty1 << endl;
cout << sName2 << ": " << iParty2 << endl;

ganador();


}
Last edited on
Sounds like a plan. You have my approval. I you have any questions, just ask.

But use code tags to post code:
[code]
your code goes here
[/code]
I need it to work, it doesn't work as I want it to do. I want that someone can put the name of a party. And then the rest could vote. And when everybody has finished it will show the results
I think I understand what you want to do,

first of all ask the user does he/she want to create a new party if they say yes create a new party you can store this party in a string or even create a struct or class which will hold more details about the party,

next display all the parties to the user( use a loop more than likely a for loop)

next ask the user to choose the part he or she wants to vote for,increment a counter for the party that was voted.

next display the results (all the counters of each party)

you will also need to put this code inside a while loop if you want the program to run constantly or until the user enters a key to exit,you may also want the program to run just once and terminate after the vote but for this you may want to store all the votes in a text file.when you finish running the program save the information to the text file,when the program starts up again read from the file to assign the counters to the data in the text file,
make sure you structure this correctly that will be the harder part.

anyway just a suggestion.
Topic archived. No new replies allowed.