need halp passing array data

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2005
Posts: 1
Reputation: willseyvilleny is an unknown quantity at this point 
Solved Threads: 0
willseyvilleny willseyvilleny is offline Offline
Newbie Poster

need halp passing array data

 
0
  #1
Dec 9th, 2005
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.

  1. #include <stdio.h> //got your standard input output header here
  2. typedef struct element_t //defines element as a data structure
  3. {
  4. int atomic_num; char name[20]; char symbol[3]; char class[20]; float weight;
  5. } element_t; //sets new type called elem
  6.  
  7.  
  8. void intro_display (void); //intro message for end user
  9.  
  10. void scan_element (); //programmer defined function for scan_element
  11.  
  12.  
  13. void print_element (element_t *,int); // programmer defined function for print_element
  14.  
  15.  
  16. int main(void) //this is the start of the main function
  17. {
  18. element_t elem[4];
  19.  
  20. intro_display();
  21.  
  22. scan_element ();
  23.  
  24. print_element(elem, 4); //calls PDF power_elem
  25.  
  26. return 0;
  27. }
  28.  
  29.  
  30.  
  31. void scan_element ()
  32. {
  33. element_t elem [4]; //initializes 4 element types
  34.  
  35. int i=0; // i is the variable used as a control for loops
  36.  
  37. for (i=0; i<4; i++) //loops input so that four elements may be entered in the data type elem
  38. {
  39.  
  40. printf("\n What is element number %d's atomic number? ",i+1); //prompts for the atomic number to be entered.
  41.  
  42. scanf("%d", &elem[i].atomic_num); //inputs user data to element's atomic number portion of the structure
  43.  
  44. printf("\n What is element number %d's full name? ",i+1); //prompts for the element number to be entered.
  45.  
  46. scanf("%s", &elem[i].name); // inputs the name of the element into the name portion of the elem structure
  47.  
  48. printf("\n What is element %d's symbol? ",i+1); //prompts the user to input the symbol or the element
  49.  
  50. scanf("%s", &elem[i].symbol); //inputs the symbol of the element into the name portion of the elem structure
  51.  
  52. printf("\n What is element %d's class? ",i+1); //prompts the end user to input the elelment's class.
  53.  
  54. scanf("%s", &elem[i].class); //inputs the elements class type
  55.  
  56. printf("\n What is element %d's atomic weight? ",i+1); //prompts the user to input the elelments atomic weight
  57.  
  58. scanf("%f/n/n", &elem[i].weight); //inputs the elements atomic weight into the weight portion of structure elem
  59.  
  60. }
  61. }
  62.  
  63. void intro_display()
  64. {
  65. printf("Welcome to Bryant's Official Atomic Weight Tabulator");
  66. }
  67.  
  68.  
  69.  
  70. void print_element( element_t *chem_ptr,int size)
  71. {
  72. printf("\n Atomic number | Name | Symbol | Class | Atomic wieght"); //a table top that breaks the file into categories
  73.  
  74. if(chem_ptr[0].atomic_num > chem_ptr[1].atomic_num)
  75. {
  76. if(chem_ptr[0].atomic_num > chem_ptr[2].atomic_num)
  77. {
  78. if(chem_ptr[0].atomic_num > chem_ptr[3].atomic_num) // simple sort function useed to determine if element 0 is largest
  79. {
  80. printf("\n%d %s %s %s %4.2f \n\n", chem_ptr[0].atomic_num, chem_ptr[0].name,
  81. chem_ptr[0].symbol,chem_ptr[0].class, chem_ptr[0].weight); // if the condition is met its stats are printed
  82. }
  83. }
  84. }
  85.  
  86. else if(chem_ptr[1].atomic_num > chem_ptr[2].atomic_num)
  87. {
  88. 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
  89. {
  90. printf("\n%d %s %s %s %4.2f \n\n", chem_ptr[1].atomic_num, chem_ptr[1].name,
  91. chem_ptr[1].symbol,chem_ptr[1].class, chem_ptr[1].weight); // if the above conditions are met the results are printed
  92. }
  93. }
  94.  
  95. else if(chem_ptr[2].atomic_num > chem_ptr[3].atomic_num) // using the logic above the if statement becomes even smaller
  96. {
  97. printf("\n%d %s %s %s %4.2f \n\n", chem_ptr[2].atomic_num, chem_ptr[2].name,
  98. chem_ptr[2].symbol,chem_ptr[2].class, chem_ptr[2].weight); // also if the condition is met it is printed to the screen
  99. }
  100.  
  101. else if(chem_ptr[3].atomic_num > chem_ptr[2].atomic_num) // using the logic above the if statement is at its final stage
  102. {
  103. printf("\n%d %s %s %s %4.2f \n\n", chem_ptr[3].atomic_num, chem_ptr[3].name,
  104. chem_ptr[3].symbol,chem_ptr[3].class,
  105. chem_ptr[3].weight); // if the conditions above were not met this is displayed to the end user.
  106. }
  107.  
  108. return;
  109. }
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: need halp passing array data

 
0
  #2
Dec 13th, 2005
think you might be in wrong forum
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: need halp passing array data

 
0
  #3
Dec 13th, 2005
Yes, by the looks of it that is C++, you will get much better help in the correct forum.

but Welcome to DaniWeb

-T
Firefox
Ewido
Tune up windows
Get detailed system information
My Fixes

Member - Alliance of Security Analysis Professionals - Since 2006
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC