| | |
need halp passing array data
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2005
Posts: 1
Reputation:
Solved Threads: 0
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.
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.
C# Syntax (Toggle Plain Text)
#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; }
Yes, by the looks of it that is C++, you will get much better help in the correct forum.
but Welcome to DaniWeb
-T
but Welcome to DaniWeb
-T
Firefox
Ewido
Tune up windows
Get detailed system information
My Fixes
Member - Alliance of Security Analysis Professionals - Since 2006
Ewido
Tune up windows
Get detailed system information
My Fixes
Member - Alliance of Security Analysis Professionals - Since 2006
![]() |
Similar Threads
- Passing 2D Array of Pointers into a function (C++)
- passing array (C)
- passing the recordset data into an Array (ASP)
- Passing array of structures into a function (C++)
- Need help passing a multi-dimensional array (C++)
- array / data comparision help (C)
- Array data not setting (C++)
Other Threads in the C# Forum
- Previous Thread: Empty Recycle bin
- Next Thread: image processing
| Thread Tools | Search this Thread |
.net access algorithm array barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom customactiondata database datagrid datagridview dataset datastructure date/time datetime datetimepicker degrees development dll draganddrop drawing encryption enum event excel file filename files form format forms function gdi+ gis gtk hash httpwebrequest image index input install java label list listbox mandelbrot math mouseclick mysql operator outlook2003 path photoshop picturebox pixelinversion pixelminversion post programming radians regex remoting richtextbox server sleep snooze socket sql statistics stream string table tables tcp text textbox thread time timer update usercontrol usercontrols validation visualstudio webbrowser webcam wia windows winforms wpf xml






