For Homework, i have to debug a program (I am a noob!) it is a voting program where you put in the amount of votes a certain candidate gets and evaluates by showing how many votes, what percentage of votes, and total. Problem is that it rounds everything and doesnt show what it is supposed to show. I got this far... Please help!
#include <iostream>
#include "string.h"
using namespace std;
int main()
{
string candidate1 = "";
string candidate2 = "";
string candidate3 = "";
int votes1, votes2, votes3, total;
float percent1, percent2, percent3, percent;
cout<<"--Vote Analysis Program--\n";
candidate1 = "Kerry";
candidate2 = "Bush";
candidate3 = "Working";
candidate2[8] = 'h';
cout<<"Enter votes for "<<candidate1<<": ";
cin>>votes1;
cout<<"Enter votes for "<<candidate2<<": ";
cin>>votes2;
cout<<"Enter votes for "<<candidate3<<": ";
cin>>votes3;
cout<<endl;
total = votes1 + votes2 + votes3;
percent1 = 100 * votes1 / total;
percent2 = 100 * votes2 / total;
percent3 = 100 * votes3 / total;
cout<< "Candidate : \t\t"<<candidate1<<endl;
cout<<"Votes: \t\t\t"<<votes1<<endl;
cout<<"Percentage: \t\t"<<percent1<<endl<<endl;
cout<< "Candidate : \t\t"<<candidate2<<endl;
cout<<"Votes: \t\t\t"<<votes2<<endl;
cout<<"Percentage: \t\t"<<percent2<<endl<<endl;
cout<< "Candidate : \t\t"<<candidate3<<endl;
cout<<"Votes: \t\t\t"<<votes3<<endl;
cout<<"Percentage: \t\t"<<percent3<<endl<<endl;
cout<<"Total Votes: \t\t"<<static_cast<float>(percent1/100 * total)
+ (percent2/100 * total) + (percent3/100 * total) <<endl<<endl;
cout<<"Total Percentage: \t"<<(percent1 + percent2+ percent3)
<<endl;
cout<<endl;
cin.get();
cin.get();
return 0;
}