I have this habit of first trying out all the exercises of the book then going on to psets. I am on chapter 7, arrays. the question was to make a program of some sort of voting counter and instead of a defined number of entries the program should end only when 999 is entered.
following is my code, I wanna know why its giving me an error of undeclared identifier on the values stored at the array of string name. Seems I can't create an array of strings, but why?
#include <stdio.h>
#include <cs50.h>
#include <string.h>
int main (void)
{
int counter[4], vote;
for (int i = 0; i < 4; i++)
{
counter[i] = 0;
}
string name[] = {PTI, MQM, PPP, PMLN};
while (true)
{
printf("press 1 to vote for %s.\npress 2 to vote for %s.\npress 3 to vote for %s.\nPress 4 to vote for %s.\n", name[0], name[1], name[2], name[3] );
vote = GetInt();
if (vote < 1 || vote > 4)
{
printf("Bad response.\n\n\n");
}
if (vote == 999)
{
break;
}
else
{
counter[vote - 1]++;
}
}
for (int i =0; i < 4; i++)
{
printf("%i votes were casted for %s.\n", counter[i], name[i]);
}
}
PTI
,MQM
,PPP
,PMLN
are string values? don't you wanna surround them with something?