I'm writing a program to display names and the number of apartments however, my array storing the names is unable to display the names saying that they're unidentified. Is there anyway to have the string contained in the array to display? Also, I seem to get the value of n displaying beneath the number of apartments in the display, is there anyway to get rid of this? Here's my code:
#include <stdio.h>
int main(void)
{
int i;
char name[] = {North, West, South, East};
int apt[] = {24, 30, 14, 18};
const int n = 5;
printf("Name No. of Apartments\n");
for (i = 0; i < n; i++)
printf("%c %d\n", name[i], apt[i]);
return 0;
}
char name[] = {North, West, South, East};is totally invalid, for starters - you didn't even put the strings in quotes, let alone define the array correctly. You wantchar * name[] = {"North", "West", "South", "East"}"North", ...%cin yourprintf, which is for single characters, not strings. You're also going through the loop 5 times when there are 4 elements, so setnto 4, not 5.