I'm working on an assignment for storing numbers and names into an array. We have to store 4 numbers to represent time in seconds into each number in the array. This is then totaled and output for each number in an English sentence--in minutes and seconds format.
Here's what I have, which is very minimal and I'm not even sure it does what it's supposed to:
#include <stdio.h>
int main()
{
int i = 0;
int person[8] = { 0 };
int leg1;
int leg2;
int leg3;
int leg4;
while (i < 8) {
printf("Hello, please enter the number of the person.:\n");
scanf("%d", &person[i]);
i = i + 1;
}
printf("%d ", i);
return 0;
}
Ideally instead of numbers I'd like to record a name for each person in the array - a total of 8 names but even the numbers I don't think work.
I'm not sure if its possible to then assign each number in the code 4 values of time using scanf.
The legs are there to store the 4 values of time and then I would sum them up and convert it to seconds and output the time for each value as a whole. I just don't know how to do it for arrays.
edit: not very used to how editing works on this, half of what I wrote is gone but that's fine most of it was all mumbo jumbo anyway. Heres the other bit of code I have that records the time and categorizes the times:
#include <stdio.h>
int main()
{
char name[31];
int leg1;
int leg2;
int leg3;
int leg4;
int totalTime;
printf("Hello, please enter the name of the person.:\n");
scanf("%30s", &name);
printf("Now please enter the time of the person for the first leg in seconds.:\n");
scanf("%d", &leg1);
printf("Now please enter the time of the person for the second leg in seconds.:\n");
scanf("%d", &leg2);
printf("Now please enter the time of the person for the third leg in seconds.:\n");
scanf("%d", &leg3);
printf("Now please enter the time of the person for the final leg in seconds.:\n");
scanf("%d", &leg4);
totalTime = leg1 + leg2 + leg3 + leg4;
int minutes = totalTime / 60;
int seconds = totalTime % 60;
if (minutes < 4)
{
printf("\t%30s qualified for the International Tournament with a time of %d minutes and %d seconds", name, minutes, seconds);
}
else if (minutes >= 4 && minutes < 12)
{
printf("\t%30s qualified for the Natonal Race Meeting with a time of %d minutes and %d seconds", name, minutes, seconds);
}
else if (minutes >= 12 && minutes < 30)
{
printf("\t%30s qualified for the Beginner's League with a time of %d minutes and %d seconds", name, minutes, seconds);
}
else if (minutes >= 30)
{
printf("\t%30s did not qualify for any league with a really shit time of %d minutes and %d seconds", name, minutes, seconds);
}
return 0;
}