I_royalty_I
12-13-2014, 08:21 PM
This program is pretty sloppy, but at this point I don't really care haha. It function, so far, how I need it to.
I'm having one issue with it that I cant figure out, though.
Basically it asks for family members names, ages, locations, then calculates the average age and outputs those who are in texas.
I need help with the /printing out those who are in texas/ part.
#include <stdio.h>
int main()
{
int i, j, k, l=0, Age = 0;
int FamilyAges[5]={0};
char FamilyMembers[5];
char Name, Location;
char FamilyLocations[5];
float TotalAge = 0;
float NumFamily = 0;
float AverageAge;
for (i=0; i<5; i++)
{
printf("Input the name of the family members: \n");
scanf("%s", &Name);
FamilyMembers[i]=Name;
}
for (i=0; i<5; i++)
{
printf("Input the age of the family members: \n");
scanf("%d", &Age);
FamilyAges[i]=Age;
TotalAge = TotalAge + Age;
NumFamily++;
}
for (i=0; i<5; i++)
{
printf("Input the Location of the family members: \n");
scanf("%s", &Location);
FamilyLocations[i]=Location;
}
printf("The total number of family members is: %f\n", NumFamily); /*for testing purposes */
printf("The total age of family members is: %f\n", TotalAge); /*for testing purposes*/
AverageAge = (TotalAge / NumFamily);
printf("The average age of the family members is %f\n", AverageAge);
return 0;
}
I tried to add in something like
while (l <= NumFamily)
{
if (FamilyLocations[l] = "Texas")
{
printf("The family member %s is from Texas\n", FamilyMembers[l]);
}
}
But I think I screwed something up, or don't have it done right.
Suggestions? D:
I'm having one issue with it that I cant figure out, though.
Basically it asks for family members names, ages, locations, then calculates the average age and outputs those who are in texas.
I need help with the /printing out those who are in texas/ part.
#include <stdio.h>
int main()
{
int i, j, k, l=0, Age = 0;
int FamilyAges[5]={0};
char FamilyMembers[5];
char Name, Location;
char FamilyLocations[5];
float TotalAge = 0;
float NumFamily = 0;
float AverageAge;
for (i=0; i<5; i++)
{
printf("Input the name of the family members: \n");
scanf("%s", &Name);
FamilyMembers[i]=Name;
}
for (i=0; i<5; i++)
{
printf("Input the age of the family members: \n");
scanf("%d", &Age);
FamilyAges[i]=Age;
TotalAge = TotalAge + Age;
NumFamily++;
}
for (i=0; i<5; i++)
{
printf("Input the Location of the family members: \n");
scanf("%s", &Location);
FamilyLocations[i]=Location;
}
printf("The total number of family members is: %f\n", NumFamily); /*for testing purposes */
printf("The total age of family members is: %f\n", TotalAge); /*for testing purposes*/
AverageAge = (TotalAge / NumFamily);
printf("The average age of the family members is %f\n", AverageAge);
return 0;
}
I tried to add in something like
while (l <= NumFamily)
{
if (FamilyLocations[l] = "Texas")
{
printf("The family member %s is from Texas\n", FamilyMembers[l]);
}
}
But I think I screwed something up, or don't have it done right.
Suggestions? D: