Calculating total distance travelled from time and varying speed
I'm writing a program in C which simulates a car dashboard. I've already got a time variable which starts counting as soon as the program starts and continues while ever it is running. I've also already got a speed variable which can be varied ranging from 0-125mph. I need to continuously calculate and display the total distance travelled for the time the program is running, while the speed is constantly changing.
If the speed was constant then it would just be a simple distance = speed x time but because the speed can be varied, if it was reduced, then the distance would reduce and go backwards!
How would i go about calculating the total distance travelled for the length of time the program is running, when the speed is constantly changing?