I am learning C and relatively new to it.
I am having trouble with Structs and I am trying to get a structure variable to hold the values firstName
, lastName
, tries
, won
, and percentage
. The last three themselves have to be contained in another struct inside the first struct. My code is below, also if anyone could explain the difference between structure tags and variable types that would help a lot. I understand there may be a lot of errors in the code.
#include <stdio.h>
#include <string.h>
struct team{
char firstName[40];
char lastName[40];
struct stats{
int tries;
int won;
float percentage;
} record;
};
int main(){
//Assign variable name and test print to check that struct is working.
struct team player;
strcpy(player.firstName,"Michael");
strcpy(player.lastName,"Jordan");
struct stats player;
player.tries = 16;
player.won = 14;
player.percentage = ((player.won/player.tries)*100);
printf("First Name: \t %s \n", player.firstName);
printf("Last Name: \t %s \n", player.lastName);
printf("Tries: \t %d \n", player.tries);
printf("Won: \t %d \n", player.won);
printf("Percentage: \t %f \n", player.percentage);
return 0;
}