Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The code below comes up with this error. I am a bit confused, any ideas on what

ID: 670844 • Letter: T

Question

The code below comes up with this error. I am a bit confused, any ideas on what I am missing??

#include <stdio.h>

#include <string>

int main()

{

int x, count=0;

float sum;

float average;

int age[10];

char name[10][100];

char state[10][100];

bool okay = true;

  

do

{

printf("Enter the family member's name. Type 'done' when complete. ");

gets(name[count]);

if ( strcmp(name[count],"DONE") || strcmp(name[count],"done"))

{

okay = false;

break;

}

  

printf("Enter family member's age " );

scanf("%d",&age[count]);

  

printf("Which state are you from? Type in CA, TX, VA, NY, VT? ");

gets(state[count]);

if ( strcmp(state[count],"CA") || strcmp(state[count],"ca"))

{

strcpy(state[count],"California");

}

else if ( strcmp(state[count],"TX") || strcmp(state[count],"tx"))

{

strcpy(state[count],"Texas");

}

else if ( strcmp(state[count],"VA") || strcmp(state[count],"va"))

{

strcpy(state[count],"Virginia");

}

  

else if ( strcmp(state[count],"NY") || strcmp(state[count],"ny"))

{

strcpy(state[count],"New York");

}

else if ( strcmp(state[count],"VT") || strcmp(state[count],"vt"))

{

strcpy(state[count],"Vermont");

}

else

{

printf("I don't understand!! ");

count--;

}

count++;

} while (okay || count != 10);

  

sum = 0.0;

average = 0.0;

for ( x=0;x<count;x++)

{

sum = sum + age[x];

}

average = sum/count;

printf(" The average age of your family is %f years old. ",average);

printf(")The entered data was : ");

for ( x=0; x < count ;x++)

{

printf("%s lives in %s and is %d years old. ",name[x],state[x],age[x]);

}

return 0;

}

Explanation / Answer

#include <stdio.h>
#include <string.h>
int main()
{
int x, count=0;
float sum;
float average;
int age[10];
char name[10][100];
char state[10][100];
int okay = 1;
  
do
{
printf("Enter the family member's name. Type 'done' when complete. ");
gets(name[count]);
if ( strcmp(name[count],"DONE") || strcmp(name[count],"done"))
{
okay = 0;
break;
}
  
printf("Enter family member's age " );
scanf("%d",&age[count]);
  
printf("Which state are you from? Type in CA, TX, VA, NY, VT? ");
gets(state[count]);
if ( strcmp(state[count],"CA") || strcmp(state[count],"ca"))
{
strcpy(state[count],"California");
}
else if ( strcmp(state[count],"TX") || strcmp(state[count],"tx"))
{
strcpy(state[count],"Texas");
}
else if ( strcmp(state[count],"VA") || strcmp(state[count],"va"))
{
strcpy(state[count],"Virginia");
}
  
else if ( strcmp(state[count],"NY") || strcmp(state[count],"ny"))
{
strcpy(state[count],"New York");
}
else if ( strcmp(state[count],"VT") || strcmp(state[count],"vt"))
{
strcpy(state[count],"Vermont");
}
else
{
printf("I don't understand!! ");
count--;
}
count++;
} while (okay || count != 10);
  
sum = 0.0;
average = 0.0;
for ( x=0;x<count;x++)
{
sum = sum + age[x];
}
average = sum/count;
printf(" The average age of your family is %f years old. ",average);
printf(")The entered data was : ");
for ( x=0; x < count ;x++)
{
printf("%s lives in %s and is %d years old. ",name[x],state[x],age[x]);
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote