Answer the question
In order to leave comments, you need to log in
How to compare values in multiple structures?
Here is the task:
The structure of the element for the array of employees: last name, first name, patronymic, age, height.
Determine:
─ the average height of employees 18-20 years old
─ the name of the tallest employee;
─ Names of employees who have the same height
I tried to make structures with the corresponding data, then add a do while loop so that the user can enter other questionnaires of employees for comparisons, and if he needs to sum up, he can do it. But when it came to making those comparisons, it became clear that I didn't know that at all. In general, it is necessary to somehow organize this business.
Here is the code as written so far:
#include <stdio.h>
#include <string.h>
int main () {
int a;
struct employee {
char surname[30];
char name[30];
char patronymic[30];
char age[2];
char growth[3];
};
employee p;
puts ("Input surame: ");
gets (p.surname);
puts ("Input name: ");
gets (p.name);
puts ("Input patronymic: ");
gets (p.patronymic);
puts ("Input age: ");
gets ("%d", &p.age);
puts ("Input growth: ");
gets ("%d", &p.growth);
loop1:
do
{
printf ("Enter 1 if you want to add another profile. If you want to get statistics, enter 0.", &a);
scanf ("%d", a);
else if (a!=0 || 1)
goto loop1
if (a=1) {
employee p;
puts ("Input surame: ");
gets (p.surname);
puts ("Input name: ");
gets (p.name);
puts ("Input patronymic: ");
gets (p.patronymic);
puts ("Input age: ");
gets ("%d", &p.age);
puts ("Input growth: ");
gets ("%d", &p.growth);
}
else if (a=0); {
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question