Try some of our tutorials, maybe they'll help: Cprogramming.com - Programming Tutorials: C++ Made Easy and C Made Easy.
Originally Posted by JonathanS
Your passing a string to a function issue is because your declared your function to take a char, not a char *. Also, your prototype is incorrect. You specify the type without a variable name, not the name without a type. The purpose of the prototype is so the compiler can check your usage: correct number and type of params, and correct return type.
You need to work on further breaking your code into functions. Your calc_valence function is a good start, but you could do a lot more. Your calc_valence function would benefit greatly from using an array to map element names to valence electrons. Also, you don't need compare or VEtemp:
You have 3 while loops in your main that are essentially the same, make one into a function, and call it 3 times, one with max1, VE, a1, a2 and a3; another with max2, VE, b1, b2 and b3, etc. Move your input gathering code into one funciton and your output code into another function.
int calc_valence(char *element) // note the * to signify pointer to character, which is typically how you pass strings in C
if (strcmp(element, "B") == 0)
if strcmp(element, "C") == 0)
return -1; // check the return value in main, and report "Invalid element" if it's -1
Pay it forward. None of us came here to make money from our posts. As you learn and become knowledgeable and an expert in your field, take some time to help out those who are struggling like you once were.
You guys help me so much I feel like I should pay you somehow :S