i need to finish this program by friday at 8:00am i know im new but i have a lot of work done so pretty much here is what i have.
requirements
programmer defined function for into - check
user must input element statistics into element_t im pretty sure i made that
programmer defined function for scan_element to get element stats and store them into element_t
print function that prints the heaviest element
now it all worked until i broke it up into pdf's so i think i jsut had issues with passing data, but im burned out and cant see in my code anymore so im asking for help.
#include <stdio.h> //got your standard input output header here
typedef struct element_t //defines element as a data structure
{
int atomic_num; char name[20]; char symbol[3]; char class[20]; float weight;
} element_t; //sets new type called elem
void intro_display (void); //intro message for end user
void scan_element (); //programmer defined function for scan_element
void print_element (element_t *,int); // programmer defined function for print_element
int main(void) //this is the start of the main function
{
element_t elem[4];
intro_display();
scan_element ();
print_element(elem, 4); //calls PDF power_elem
return 0;
}
void scan_element ()
{
element_t elem [4]; //initializes 4 element types
int i=0; // i is the variable used as a control for loops
for (i=0; i<4; i++) //loops input so that four elements may be entered in the data type elem
{
printf("\n What is element number %d's atomic number? ",i+1); //prompts for the atomic number to be entered.
scanf("%d", &elem[i].atomic_num); //inputs user data to element's atomic number portion of the structure
printf("\n What is element number %d's full name? ",i+1); //prompts for the element number to be entered.
scanf("%s", &elem[i].name); // inputs the name of the element into the name portion of the elem structure
printf("\n What is element %d's symbol? ",i+1); //prompts the user to input the symbol or the element
scanf("%s", &elem[i].symbol); //inputs the symbol of the element into the name portion of the elem structure
printf("\n What is element %d's class? ",i+1); //prompts the end user to input the elelment's class.
scanf("%s", &elem[i].class); //inputs the elements class type
printf("\n What is element %d's atomic weight? ",i+1); //prompts the user to input the elelments atomic weight
scanf("%f/n/n", &elem[i].weight); //inputs the elements atomic weight into the weight portion of structure elem
}
}
void intro_display()
{
printf("Welcome to Bryant's Official Atomic Weight Tabulator");
}
void print_element( element_t *chem_ptr,int size)
{
printf("\n Atomic number | Name | Symbol | Class | Atomic wieght"); //a table top that breaks the file into categories
if(chem_ptr[0].atomic_num > chem_ptr[1].atomic_num)
{
if(chem_ptr[0].atomic_num > chem_ptr[2].atomic_num)
{
if(chem_ptr[0].atomic_num > chem_ptr[3].atomic_num) // simple sort function useed to determine if element 0 is largest
{
printf("\n%d %s %s %s %4.2f \n\n", chem_ptr[0].atomic_num, chem_ptr[0].name,
chem_ptr[0].symbol,chem_ptr[0].class, chem_ptr[0].weight); // if the condition is met its stats are printed
}
}
}
else if(chem_ptr[1].atomic_num > chem_ptr[2].atomic_num)
{
if(chem_ptr[1].atomic_num > chem_ptr[3].atomic_num) // because chem_ptr[0] has been eliminated the test is even smaller but that same concept applies
{
printf("\n%d %s %s %s %4.2f \n\n", chem_ptr[1].atomic_num, chem_ptr[1].name,
chem_ptr[1].symbol,chem_ptr[1].class, chem_ptr[1].weight); // if the above conditions are met the results are printed
}
}
else if(chem_ptr[2].atomic_num > chem_ptr[3].atomic_num) // using the logic above the if statement becomes even smaller
{
printf("\n%d %s %s %s %4.2f \n\n", chem_ptr[2].atomic_num, chem_ptr[2].name,
chem_ptr[2].symbol,chem_ptr[2].class, chem_ptr[2].weight); // also if the condition is met it is printed to the screen
}
else if(chem_ptr[3].atomic_num > chem_ptr[2].atomic_num) // using the logic above the if statement is at its final stage
{
printf("\n%d %s %s %s %4.2f \n\n", chem_ptr[3].atomic_num, chem_ptr[3].name,
chem_ptr[3].symbol,chem_ptr[3].class,
chem_ptr[3].weight); // if the conditions above were not met this is displayed to the end user.
}
return;
}