I cannot understand why the results of my division appear rounded down?
#include <iostream>
#include <stdio.h>
using namespace std;
int rVote, oVote, dVote;
int rTotal, oTotal, dTotal, total;
int rPercent, dPercent, oPercent;
bool loop(char vote){
switch(toupper(vote)){
case 'D':
dVote = 1;
dTotal = dTotal + dVote;
return true;
case 'R':
rVote = 1;
rTotal = rTotal + rVote;
return true;
case 'O':
oVote = 1;
oTotal = oTotal + oVote;
return true;
case 'Q':
return false;
}
return true;
}
int main(){
char vote;
do{
printf("Enter Vote [D/R/O] or Q to quit: ");
scanf("%c%*c", &vote);
} while (loop(vote));
total = dTotal + rTotal + oTotal;
rPercent = ((rTotal/total)*100);
dPercent = ((dTotal/total)*100);
oPercent = ((oTotal/total)*100);
printf("Democrate total vote %d: %d%%\n", dTotal, dPercent);
printf("Republican total vote %d: %d%%\n", rTotal, rPercent);
printf("Other total vote %d: %d%%\n", oTotal, oPercent);
}
Great I am being really dumb....
Why is it that any of my *Percent
's not printing the % value in this c/c++ program?
Thanks.