I have this program and in the first loop of the while it runs normally, printa only once each thing, but in the second loop it printa "Type S to vote, N to see the calculation of the votes and leave." twice before reading. Can anyone tell me why?
#include "pch.h"
#include <iostream>
#include <locale.h>
int main() {
char resp;
int presidente[15], governador[12], votop = 0, votog = 0, i = 0, x=2;
while (x != 0) {
printf ("Digite S para votar, N para ver a apuracao dos votos e sair. ");
fflush(stdin);
resp = getchar();
if (resp == 's' || resp == 'S') {
printf("\n\n\n Digite o numero para presidente: ");
fflush(stdin);
scanf_s("%d", &votop);
i = votop;
presidente[i] = presidente[i] + 1;
printf("\n\nAgora digite o numero para gorvernador: ");
fflush(stdin);
scanf_s("%d", &votog);
i = votog;
governador[i] = governador[i] + 1;
printf("\n\n\nObrigado por votar.\n\n\n");
}
if (resp == 'n' || resp == 'N') {
x = 0;
}
}
printf("\n\n\n");
system("pause");
return 0;
}