So I have this homework about Elections.
the user inputs 3 letters , each one represents a group of parties .
for example the input is : A D H
first group of parties : A B C
second : D E F G
third : H-Z
the next input will be the votes , doesnt matter a capital letter or small . if the inpute of votes for examlpe is : aBcEgQ
the output should be that :
first group got : 3
second: 2
third:1
now to the problem im facing , im using this codethe problem is that if I entered the input as explained in the example above the output is :Code:#include <stdio.h> #include <stdlib.h> int main() { char a[100]; char X,Y,Z; int score1=0; int score2=0; int score3=0; printf("Welcome to the 2015 elections!\n"); printf("Please enter the camps leaders:\n"); scanf(" %c %c %c", &X , &Y, &Z); printf("Please enter the votes:\n"); scanf(" %s",a); int n=0 ; for(int i = n ; i<=100 ; i++ ) { if( X>=a[i] ) { score1++; } if(X<a[i] && a[i]<=Y) { score2++; } if(Y<a[i] && a[i]<=Z) { score3++; } } printf("score1 is : %d\n",score1); printf("score1 is : %d\n",score2); printf("score1 is : %d\n",score3); return 0; }
score1 is :81
score2 is :1
score3 is :3
what is the problem !? I think im missing something or things actually :\
thanks guys