Here is my code where I have 3 functions that do simple arithmetic:
#include <stdio.h>
/* The following Code Contains 3 functions
* that compute simple arithmetic such as
* computing the sum of 3 integers and divison
* of three floating integers.
*/
void getSum(int x, int y, int z);
double doDiv(float one, float two, float three);
void getDiv(float a, float b, float c);
int main()
{
getSum(100,242,62);
getDiv(100.0,25.0,2.0);
return 0;
}
/*The function getSum accepts three int
*values and computes the sum of all three and prints
*the result via standard output.
*/
void getSum(int x, int y, int z)
{
int sum = x + y + z;
printf("%i\n",sum);
}
/*The function doDiv accepts three floating
*values and computes the divison of first two.
*Finally it divides the result by the third
* floating value and returns the final answer.
*/
double doDiv(float one,float two, float three)
{
float answer;
answer = one/two;
answer = answer/three;
return answer;
}
/* The function getDiv accepts three floating values
* and then calls the doDiv function. The three accepted
* values are passed as parameters in the function call.
*/
void getDiv(float a, float b, float c)
{
float finalAnswer;
finalAnswer = doDiv(a,b,c);
printf("%f\n", finalAnswer);
}
I have tried my best to comment each function but I am not sure if I am doing it correctly. Can someone please advise me on making my comments better, naming variables better and anything else that can help me utilize coding standards correctly?
I would like to pick up the habit now while I am still writing small lines of code so I can take it forward with me when I write bigger codes.
Any suggestions on how I can comment better, name variables better, write code more elegant are welcome. Also, do I comment the method declarations on top?