I'm pretty new to C programming and I had a question as to why a sample code I was given runs the way it does. I'm learning about function prototypes. Can someone give me a run down on the order in which this compiles?
//TwoFunctions - All code split into two user-defined functions
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
//function prototypes
//Calculates and displays the total and avergae of two numbers
void CalcAvg(double tot);
double CalcTotal();
int main()
{
double totl;
totl = CalcTotal();
CalcAvg(totl);
printf("Your total is %.2f\n", totl);
return 0;
}
CalcTotal()
{
double val,
num,
total;
printf("Please enter a number: ");
scanf(" %lf", &num);
printf("Please enter another number: ");
scanf(" %lf", &val);
total = val + num;
return total;
}
void CalcAvg(double tot)
{
double avg;
avg = tot/2;
//printf("Your total is %.2f\n", tot);
printf("The average of the two numbers is %.2f\n", avg);
return;
}
If it makes any sense, for the most part I understand and can write a program like that, however I am a little unclear as to the the steps involved, the calls, and the order in which the compiler compiles the program. Can someone shed a little light on this for? Greatly appreciate it!